erpnext-queue-client 1.38.0 → 2.0.0-beta.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 +2 -2
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +16 -2
- package/dist/erpnext/doctypeResourceRequest.d.ts +12 -11
- package/dist/erpnext/doctypeResourceRequest.js +3 -2
- package/dist/erpnext/doctypeSubmittableResourceRequest.d.ts +121 -4
- package/dist/erpnext/doctypeSubmittableResourceRequest.js +14 -1
- package/dist/erpnext/doctypes/address.d.ts +154 -219
- package/dist/erpnext/doctypes/address.js +0 -2
- package/dist/erpnext/doctypes/contact.d.ts +151 -308
- package/dist/erpnext/doctypes/contact.js +1 -1
- package/dist/erpnext/doctypes/deliveryNote.d.ts +644 -455
- package/dist/erpnext/doctypes/deliveryNote.js +4 -10
- package/dist/erpnext/doctypes/item.d.ts +215 -308
- package/dist/erpnext/doctypes/productBundle.d.ts +43 -53
- package/dist/erpnext/doctypes/purchaseInvoice.d.ts +669 -697
- package/dist/erpnext/doctypes/purchaseReceipt.d.ts +265 -314
- package/dist/erpnext/doctypes/salesInvoice.d.ts +3332 -0
- package/dist/erpnext/doctypes/salesInvoice.js +72 -0
- package/dist/erpnext/doctypes/servicecase.d.ts +197 -140
- package/dist/erpnext/doctypes/servicecase.js +4 -6
- package/dist/erpnext/doctypes/shipment.d.ts +168 -258
- package/dist/erpnext/doctypes/tags.d.ts +10 -0
- package/dist/erpnext/doctypes/tags.js +102 -0
- package/dist/erpnext/model/Account.d.ts +0 -33
- package/dist/erpnext/model/Account.js +0 -11
- package/dist/erpnext/model/Address.d.ts +112 -233
- package/dist/erpnext/model/Address.js +11 -49
- package/dist/erpnext/model/Attachment.d.ts +0 -3
- package/dist/erpnext/model/Attachment.js +0 -1
- package/dist/erpnext/model/Boolean.d.ts +4 -0
- package/dist/erpnext/model/Boolean.js +9 -0
- package/dist/erpnext/model/Compliance.d.ts +0 -112
- package/dist/erpnext/model/Compliance.js +0 -19
- package/dist/erpnext/model/Contact.d.ts +166 -416
- package/dist/erpnext/model/Contact.js +16 -69
- package/dist/erpnext/model/Country.d.ts +0 -64
- package/dist/erpnext/model/Country.js +0 -10
- package/dist/erpnext/model/Customer.d.ts +39 -64
- package/dist/erpnext/model/Customer.js +11 -25
- package/dist/erpnext/model/DeliveryNote.d.ts +124 -1170
- package/dist/erpnext/model/DeliveryNote.js +5 -52
- package/dist/erpnext/model/DispatchRun.d.ts +7 -113
- package/dist/erpnext/model/DispatchRun.js +2 -31
- package/dist/erpnext/model/DispatcherPreset.d.ts +0 -119
- package/dist/erpnext/model/DispatcherPreset.js +1 -27
- package/dist/erpnext/model/DocInfo.d.ts +41 -339
- package/dist/erpnext/model/DocInfo.js +5 -6
- package/dist/erpnext/model/DocTypeHelpers.d.ts +141 -2
- package/dist/erpnext/model/DocTypeHelpers.js +132 -1
- package/dist/erpnext/model/ERPNextDocTypeMeta.d.ts +124 -0
- package/dist/erpnext/model/ERPNextDocTypeMeta.js +37 -0
- package/dist/erpnext/model/ERPNextRequest.d.ts +5 -5
- package/dist/erpnext/model/File.d.ts +0 -48
- package/dist/erpnext/model/File.js +0 -8
- package/dist/erpnext/model/Fulfiller.d.ts +0 -121
- package/dist/erpnext/model/Fulfiller.js +1 -56
- package/dist/erpnext/model/FulfillerSettings.d.ts +0 -39
- package/dist/erpnext/model/FulfillerSettings.js +0 -6
- package/dist/erpnext/model/InternalReasons.d.ts +0 -3
- package/dist/erpnext/model/InternalReasons.js +0 -1
- package/dist/erpnext/model/Item.d.ts +478 -1847
- package/dist/erpnext/model/Item.js +18 -142
- package/dist/erpnext/model/Logs.d.ts +0 -9
- package/dist/erpnext/model/Logs.js +0 -3
- package/dist/erpnext/model/PartList.d.ts +0 -15
- package/dist/erpnext/model/PartList.js +0 -5
- package/dist/erpnext/model/PaymentEntry.d.ts +141 -128
- package/dist/erpnext/model/PaymentEntry.js +46 -47
- package/dist/erpnext/model/Permissions.d.ts +3 -3
- package/dist/erpnext/model/Permissions.js +1 -1
- package/dist/erpnext/model/ProductBundle.d.ts +6 -107
- package/dist/erpnext/model/ProductBundle.js +0 -17
- package/dist/erpnext/model/PurchaseInvoice.d.ts +290 -362
- package/dist/erpnext/model/PurchaseInvoice.js +5 -23
- package/dist/erpnext/model/PurchaseOrder.d.ts +34 -180
- package/dist/erpnext/model/PurchaseOrder.js +0 -34
- package/dist/erpnext/model/Receipt.d.ts +30 -121
- package/dist/erpnext/model/Receipt.js +2 -25
- package/dist/erpnext/model/ReceiptDraft.d.ts +28 -67
- package/dist/erpnext/model/ReceiptDraft.js +2 -11
- package/dist/erpnext/model/Report.d.ts +0 -40
- package/dist/erpnext/model/Report.js +0 -8
- package/dist/erpnext/model/SalesInvoice.d.ts +2441 -0
- package/dist/erpnext/model/SalesInvoice.js +326 -0
- package/dist/erpnext/model/SalesOrder.d.ts +1043 -0
- package/dist/erpnext/model/SalesOrder.js +271 -0
- package/dist/erpnext/model/SalesTaxesAndCharges.d.ts +47 -0
- package/dist/erpnext/model/SalesTaxesAndCharges.js +30 -0
- package/dist/erpnext/model/Servicecase.d.ts +295 -740
- package/dist/erpnext/model/Servicecase.js +31 -116
- package/dist/erpnext/model/ServicecaseReason.d.ts +0 -8
- package/dist/erpnext/model/ServicecaseReason.js +0 -2
- package/dist/erpnext/model/ServicecaseSolution.d.ts +0 -3
- package/dist/erpnext/model/ServicecaseSolution.js +0 -1
- package/dist/erpnext/model/ServiceportalProductConfiguration.d.ts +0 -575
- package/dist/erpnext/model/ServiceportalProductConfiguration.js +5 -50
- package/dist/erpnext/model/Shipment.d.ts +18 -729
- package/dist/erpnext/model/Shipment.js +1 -82
- package/dist/erpnext/model/ShippingLabel.d.ts +0 -32
- package/dist/erpnext/model/ShippingLabel.js +0 -8
- package/dist/erpnext/model/ShippingProvider.d.ts +6 -87
- package/dist/erpnext/model/ShippingProvider.js +3 -6
- package/dist/erpnext/model/Stock.d.ts +6 -46
- package/dist/erpnext/model/Stock.js +0 -8
- package/dist/erpnext/model/StockEntry.d.ts +12 -45
- package/dist/erpnext/model/StockEntry.js +0 -11
- package/dist/erpnext/model/StockReconciliation.d.ts +5 -32
- package/dist/erpnext/model/StockReconciliation.js +0 -10
- package/dist/erpnext/model/Supplier.d.ts +0 -79
- package/dist/erpnext/model/Supplier.js +0 -8
- package/dist/erpnext/model/Version.d.ts +0 -9
- package/dist/erpnext/model/Version.js +0 -3
- package/dist/erpnext/model/Waitlist.d.ts +0 -3
- package/dist/erpnext/model/Waitlist.js +0 -1
- package/dist/erpnext/model/WarehouseCategory.d.ts +0 -11
- package/dist/erpnext/model/WarehouseCategory.js +1 -7
- package/dist/erpnext/reports.js +3 -7
- package/dist/erpnext/resourceRequest.d.ts +13 -11
- package/dist/erpnext/resourceRequest.js +23 -18
- package/dist/index.d.ts +16 -10
- package/dist/index.js +24 -12
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +227 -0
- package/dist/utils/utils.d.ts +3 -0
- package/dist/utils/zodContextOptionals.d.ts +14 -0
- package/dist/utils/zodContextOptionals.js +42 -0
- package/dist/utils/zodUtils.js +2 -1
- package/package.json +2 -2
- package/dist/erpnext/model/ConsolidatedCustomsInvoice.d.ts +0 -433
- package/dist/erpnext/model/ConsolidatedCustomsInvoice.js +0 -102
- package/dist/erpnext/model/ShippingFees.d.ts +0 -36
- package/dist/erpnext/model/ShippingFees.js +0 -18
|
@@ -11,14 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ERPNextResourceRequest = void 0;
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
|
+
const logger_1 = require("../utils/logger");
|
|
15
|
+
const utils_1 = require("../utils/utils");
|
|
14
16
|
const zodUtils_1 = require("../utils/zodUtils");
|
|
17
|
+
const DocTypeHelpers_1 = require("./model/DocTypeHelpers");
|
|
15
18
|
const ERPNextResponse_1 = require("./model/ERPNextResponse");
|
|
16
|
-
const
|
|
17
|
-
const logger_1 = require("../utils/logger");
|
|
19
|
+
const zodContextOptionals_1 = require("../utils/zodContextOptionals");
|
|
18
20
|
class ERPNextResourceRequest {
|
|
19
21
|
constructor(temporalClient) {
|
|
20
22
|
this.getParams = (fields, filters, asDict, params) => {
|
|
21
|
-
const fieldsParams = fields
|
|
23
|
+
const fieldsParams = fields
|
|
24
|
+
? { fields: `[${fields.map((fi) => `"${fi}"`).join(",")}]` }
|
|
25
|
+
: {};
|
|
22
26
|
const filtersParams = filters
|
|
23
27
|
? {
|
|
24
28
|
filters: `[${filters
|
|
@@ -36,7 +40,9 @@ class ERPNextResourceRequest {
|
|
|
36
40
|
return __awaiter(this, arguments, void 0, function* ({ resourceName, fields, filters, resourceModel, skip, limit, priority = 5, asDict, params, }) {
|
|
37
41
|
if (resourceModel && !resourceModel.description)
|
|
38
42
|
throw new Error("Resource model must have a description");
|
|
39
|
-
const erpNextFields = (fields === null || fields === void 0 ? void 0 : fields.length)
|
|
43
|
+
const erpNextFields = (fields === null || fields === void 0 ? void 0 : fields.length)
|
|
44
|
+
? fields
|
|
45
|
+
: ["name"]; // default field is name
|
|
40
46
|
const schema = asDict === false
|
|
41
47
|
? zod_1.z
|
|
42
48
|
.object({
|
|
@@ -48,13 +54,14 @@ class ERPNextResourceRequest {
|
|
|
48
54
|
: resourceModel
|
|
49
55
|
? (fields === null || fields === void 0 ? void 0 : fields[0]) === "*"
|
|
50
56
|
? zod_1.z
|
|
51
|
-
.object({ data: zod_1.z.array(
|
|
52
|
-
.describe(`${
|
|
57
|
+
.object({ data: zod_1.z.array((0, DocTypeHelpers_1.DocModelListEntry)(resourceModel)) })
|
|
58
|
+
.describe(`${resourceName} List with all fields`)
|
|
53
59
|
: zod_1.z
|
|
54
60
|
.object({
|
|
55
|
-
data: zod_1.z.array((0, zodUtils_1.pickFromSchema)(resourceModel, erpNextFields))
|
|
61
|
+
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
|
|
62
|
+
)),
|
|
56
63
|
})
|
|
57
|
-
.describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields)}`)
|
|
64
|
+
.describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields.filter((f) => f !== "*"))}`)
|
|
58
65
|
: zod_1.z.any().describe("Any response");
|
|
59
66
|
const defaultPaginationSize = 500;
|
|
60
67
|
let loopLimit = defaultPaginationSize;
|
|
@@ -67,7 +74,7 @@ class ERPNextResourceRequest {
|
|
|
67
74
|
logger_1.lg.info("AUTO PAGINATE");
|
|
68
75
|
do {
|
|
69
76
|
// use limit & skip whenever it is directly provided. In other cases use loopLimit & loopSkip to remove pagination
|
|
70
|
-
const paramsString = (0, utils_1.paramsToString)(Object.assign(Object.assign(Object.assign({}, this.getParams(
|
|
77
|
+
const paramsString = (0, utils_1.paramsToString)(Object.assign(Object.assign(Object.assign({}, this.getParams(erpNextFields, filters, asDict, params)), (limit === undefined && !autoPaginate
|
|
71
78
|
? {}
|
|
72
79
|
: { limit: String(limit !== null && limit !== void 0 ? limit : loopLimit) })), (skip === undefined && !autoPaginate
|
|
73
80
|
? {}
|
|
@@ -97,8 +104,8 @@ class ERPNextResourceRequest {
|
|
|
97
104
|
resourceId,
|
|
98
105
|
responseValidationModel: resourceModel
|
|
99
106
|
? zod_1.z
|
|
100
|
-
.object({ data: resourceModel })
|
|
101
|
-
.describe(
|
|
107
|
+
.object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) })
|
|
108
|
+
.describe(resourceName + " Response")
|
|
102
109
|
: undefined,
|
|
103
110
|
}, "erpnext", priority);
|
|
104
111
|
if (!result.data)
|
|
@@ -108,8 +115,6 @@ class ERPNextResourceRequest {
|
|
|
108
115
|
}
|
|
109
116
|
updateById(_a) {
|
|
110
117
|
return __awaiter(this, arguments, void 0, function* ({ resourceName, resourceId, inputValidationModel, resourceModel, body, priority = 5, }) {
|
|
111
|
-
if (resourceModel && !resourceModel.description)
|
|
112
|
-
throw new Error("Resource model must have a description");
|
|
113
118
|
// accept partial input while enforcing allowed keys
|
|
114
119
|
const partialInputValidationModel = inputValidationModel && inputValidationModel instanceof zod_1.ZodObject
|
|
115
120
|
? inputValidationModel.partial().strict()
|
|
@@ -120,9 +125,7 @@ class ERPNextResourceRequest {
|
|
|
120
125
|
resourceName,
|
|
121
126
|
inputValidationModel: partialInputValidationModel,
|
|
122
127
|
responseValidationModel: resourceModel
|
|
123
|
-
? zod_1.z
|
|
124
|
-
.object({ data: resourceModel })
|
|
125
|
-
.describe(resourceModel.description)
|
|
128
|
+
? zod_1.z.object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) }).describe(resourceName)
|
|
126
129
|
: undefined,
|
|
127
130
|
body,
|
|
128
131
|
}, "erpnext", priority);
|
|
@@ -136,10 +139,12 @@ class ERPNextResourceRequest {
|
|
|
136
139
|
const result = yield this.temporalClient.executeERPNextRequestWorkflow(`POST-${resourceName}`, {
|
|
137
140
|
requestMethod: "POST",
|
|
138
141
|
resourceName,
|
|
139
|
-
inputValidationModel,
|
|
142
|
+
inputValidationModel: inputValidationModel !== null && inputValidationModel !== void 0 ? inputValidationModel : (resourceModel ? (0, zodContextOptionals_1.ResourceInput)(resourceModel) : undefined),
|
|
140
143
|
responseValidationModel: resourceModel
|
|
141
144
|
? zod_1.z
|
|
142
|
-
.object({
|
|
145
|
+
.object({
|
|
146
|
+
data: (0, DocTypeHelpers_1.DocModel)(resourceModel),
|
|
147
|
+
})
|
|
143
148
|
.describe(resourceModel.description)
|
|
144
149
|
: undefined,
|
|
145
150
|
params: (0, utils_1.paramsToString)(params),
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,14 @@ import { ERPNextAddress } from "./erpnext/doctypes/address";
|
|
|
4
4
|
import { ERPNextContact } from "./erpnext/doctypes/contact";
|
|
5
5
|
import { ERPNextDeliveryNote } from "./erpnext/doctypes/deliveryNote";
|
|
6
6
|
import { ERPNextItem } from "./erpnext/doctypes/item";
|
|
7
|
+
import { ERPNextProductBundle } from "./erpnext/doctypes/productBundle";
|
|
7
8
|
import { ERPNextPurchaseInvoice } from "./erpnext/doctypes/purchaseInvoice";
|
|
8
9
|
import { ERPNextPurchaseReceipt } from "./erpnext/doctypes/purchaseReceipt";
|
|
10
|
+
import { ERPNextSalesInvoice } from "./erpnext/doctypes/salesInvoice";
|
|
11
|
+
import { ERPNextServicecase } from "./erpnext/doctypes/servicecase";
|
|
9
12
|
import { ERPNextShipment } from "./erpnext/doctypes/shipment";
|
|
10
|
-
import { ERPNextProductBundle } from "./erpnext/doctypes/productBundle";
|
|
11
13
|
import { ERPNextStock } from "./erpnext/doctypes/stock";
|
|
14
|
+
import { ERPNextTags } from "./erpnext/doctypes/tags";
|
|
12
15
|
import { ERPNextDoctypeSubmittableResourceRequest } from "./erpnext/doctypeSubmittableResourceRequest";
|
|
13
16
|
import { ERPNextFileRequests } from "./erpnext/fileRequests";
|
|
14
17
|
import { ERPNextMethodRequest } from "./erpnext/methodRequest";
|
|
@@ -16,9 +19,16 @@ import { Compliance } from "./erpnext/model/Compliance";
|
|
|
16
19
|
import { Country } from "./erpnext/model/Country";
|
|
17
20
|
import { Customer } from "./erpnext/model/Customer";
|
|
18
21
|
import { ERPNextQueueClientContructorOptions } from "./erpnext/model/ERPNextQueue";
|
|
22
|
+
import { ERPNextFile } from "./erpnext/model/File";
|
|
23
|
+
import { InternalReason } from "./erpnext/model/InternalReasons";
|
|
19
24
|
import { PartList } from "./erpnext/model/PartList";
|
|
20
25
|
import { PaymentEntry } from "./erpnext/model/PaymentEntry";
|
|
21
26
|
import { PurchaseOrder } from "./erpnext/model/PurchaseOrder";
|
|
27
|
+
import { SalesOrder } from "./erpnext/model/SalesOrder";
|
|
28
|
+
import { ServicecaseReason } from "./erpnext/model/ServicecaseReason";
|
|
29
|
+
import { ServiceCaseSolution } from "./erpnext/model/ServicecaseSolution";
|
|
30
|
+
import { ServiceportalProductConfiguration } from "./erpnext/model/ServiceportalProductConfiguration";
|
|
31
|
+
import { ShippingLabel } from "./erpnext/model/ShippingLabel";
|
|
22
32
|
import { ShippingProvider } from "./erpnext/model/ShippingProvider";
|
|
23
33
|
import { StockEntry } from "./erpnext/model/StockEntry";
|
|
24
34
|
import { StockReconciliation } from "./erpnext/model/StockReconciliation";
|
|
@@ -26,14 +36,6 @@ import { Supplier } from "./erpnext/model/Supplier";
|
|
|
26
36
|
import { Waitlist } from "./erpnext/model/Waitlist";
|
|
27
37
|
import { ERPNextReports } from "./erpnext/reports";
|
|
28
38
|
import { ERPNextResourceRequest } from "./erpnext/resourceRequest";
|
|
29
|
-
import { ERPNextServicecase } from "./erpnext/doctypes/servicecase";
|
|
30
|
-
import { ServiceportalProductConfiguration } from "./erpnext/model/ServiceportalProductConfiguration";
|
|
31
|
-
import { ShippingLabel } from "./erpnext/model/ShippingLabel";
|
|
32
|
-
import { ServicecaseReason } from "./erpnext/model/ServicecaseReason";
|
|
33
|
-
import { ServiceCaseSolution } from "./erpnext/model/ServicecaseSolution";
|
|
34
|
-
import { InternalReason } from "./erpnext/model/InternalReasons";
|
|
35
|
-
import { ERPNextFile } from "./erpnext/model/File";
|
|
36
|
-
import { ConsolidatedCustomsInvoice } from "./erpnext/model/ConsolidatedCustomsInvoice";
|
|
37
39
|
export declare class ERPNextQueueClient {
|
|
38
40
|
temporalClient: TemporalClient;
|
|
39
41
|
private credentials?;
|
|
@@ -61,6 +63,8 @@ export declare class ERPNextQueueClient {
|
|
|
61
63
|
reports: ERPNextReports;
|
|
62
64
|
compliance: ERPNextDoctypeResourceRequest<typeof Compliance>;
|
|
63
65
|
partList: ERPNextDoctypeResourceRequest<typeof PartList>;
|
|
66
|
+
salesOrder: ERPNextDoctypeSubmittableResourceRequest<typeof SalesOrder>;
|
|
67
|
+
salesInvoice: ERPNextSalesInvoice;
|
|
64
68
|
servicecase: ERPNextServicecase;
|
|
65
69
|
serviceportalProductConfiguration: ERPNextDoctypeResourceRequest<typeof ServiceportalProductConfiguration>;
|
|
66
70
|
servicecaseReason: ERPNextDoctypeResourceRequest<typeof ServicecaseReason>;
|
|
@@ -68,7 +72,7 @@ export declare class ERPNextQueueClient {
|
|
|
68
72
|
internalReason: ERPNextDoctypeResourceRequest<typeof InternalReason>;
|
|
69
73
|
shippingLabel: ERPNextDoctypeResourceRequest<typeof ShippingLabel>;
|
|
70
74
|
file: ERPNextDoctypeResourceRequest<typeof ERPNextFile>;
|
|
71
|
-
|
|
75
|
+
tags: ERPNextTags;
|
|
72
76
|
/**
|
|
73
77
|
* @description Provide either a temporal client or connection details to create a new client
|
|
74
78
|
*/
|
|
@@ -79,3 +83,5 @@ export declare class ERPNextQueueClient {
|
|
|
79
83
|
}
|
|
80
84
|
export { ERPNextMethodResponse, ERPNextMethodResponseType, ERPNextResourceResponse, ERPNextResourceResponseType, } from "./erpnext/model/ERPNextResponse";
|
|
81
85
|
export { pickFromSchema } from "./utils/zodUtils";
|
|
86
|
+
export { AugmentChildTableArrays, CreateChildTableEntrySchema, DocTypeList, LoadDocumentWrapper, } from "./erpnext/model/DocTypeHelpers";
|
|
87
|
+
export { DocTypeChildTableEntryMeta, DocTypeMeta, DocTypeNested, } from "./erpnext/model/ERPNextDocTypeMeta";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pickFromSchema = exports.ERPNextResourceResponse = exports.ERPNextMethodResponse = exports.ERPNextQueueClient = void 0;
|
|
3
|
+
exports.DocTypeNested = exports.DocTypeMeta = exports.DocTypeChildTableEntryMeta = exports.LoadDocumentWrapper = exports.DocTypeList = exports.CreateChildTableEntrySchema = exports.AugmentChildTableArrays = exports.pickFromSchema = exports.ERPNextResourceResponse = exports.ERPNextMethodResponse = exports.ERPNextQueueClient = void 0;
|
|
4
4
|
const client_1 = require("./client");
|
|
5
5
|
const decryptFromErpNext_server_1 = require("./erpnext/decryptFromErpNext.server");
|
|
6
6
|
const doctypeResourceRequest_1 = require("./erpnext/doctypeResourceRequest");
|
|
@@ -8,20 +8,30 @@ const address_1 = require("./erpnext/doctypes/address");
|
|
|
8
8
|
const contact_1 = require("./erpnext/doctypes/contact");
|
|
9
9
|
const deliveryNote_1 = require("./erpnext/doctypes/deliveryNote");
|
|
10
10
|
const item_1 = require("./erpnext/doctypes/item");
|
|
11
|
+
const productBundle_1 = require("./erpnext/doctypes/productBundle");
|
|
11
12
|
const purchaseInvoice_1 = require("./erpnext/doctypes/purchaseInvoice");
|
|
12
13
|
const purchaseReceipt_1 = require("./erpnext/doctypes/purchaseReceipt");
|
|
14
|
+
const salesInvoice_1 = require("./erpnext/doctypes/salesInvoice");
|
|
15
|
+
const servicecase_1 = require("./erpnext/doctypes/servicecase");
|
|
13
16
|
const shipment_1 = require("./erpnext/doctypes/shipment");
|
|
14
|
-
const productBundle_1 = require("./erpnext/doctypes/productBundle");
|
|
15
17
|
const stock_1 = require("./erpnext/doctypes/stock");
|
|
18
|
+
const tags_1 = require("./erpnext/doctypes/tags");
|
|
16
19
|
const doctypeSubmittableResourceRequest_1 = require("./erpnext/doctypeSubmittableResourceRequest");
|
|
17
20
|
const fileRequests_1 = require("./erpnext/fileRequests");
|
|
18
21
|
const methodRequest_1 = require("./erpnext/methodRequest");
|
|
19
22
|
const Compliance_1 = require("./erpnext/model/Compliance");
|
|
20
23
|
const Country_1 = require("./erpnext/model/Country");
|
|
21
24
|
const Customer_1 = require("./erpnext/model/Customer");
|
|
25
|
+
const File_1 = require("./erpnext/model/File");
|
|
26
|
+
const InternalReasons_1 = require("./erpnext/model/InternalReasons");
|
|
22
27
|
const PartList_1 = require("./erpnext/model/PartList");
|
|
23
28
|
const PaymentEntry_1 = require("./erpnext/model/PaymentEntry");
|
|
24
29
|
const PurchaseOrder_1 = require("./erpnext/model/PurchaseOrder");
|
|
30
|
+
const SalesOrder_1 = require("./erpnext/model/SalesOrder");
|
|
31
|
+
const ServicecaseReason_1 = require("./erpnext/model/ServicecaseReason");
|
|
32
|
+
const ServicecaseSolution_1 = require("./erpnext/model/ServicecaseSolution");
|
|
33
|
+
const ServiceportalProductConfiguration_1 = require("./erpnext/model/ServiceportalProductConfiguration");
|
|
34
|
+
const ShippingLabel_1 = require("./erpnext/model/ShippingLabel");
|
|
25
35
|
const ShippingProvider_1 = require("./erpnext/model/ShippingProvider");
|
|
26
36
|
const StockEntry_1 = require("./erpnext/model/StockEntry");
|
|
27
37
|
const StockReconciliation_1 = require("./erpnext/model/StockReconciliation");
|
|
@@ -29,14 +39,6 @@ const Supplier_1 = require("./erpnext/model/Supplier");
|
|
|
29
39
|
const Waitlist_1 = require("./erpnext/model/Waitlist");
|
|
30
40
|
const reports_1 = require("./erpnext/reports");
|
|
31
41
|
const resourceRequest_1 = require("./erpnext/resourceRequest");
|
|
32
|
-
const servicecase_1 = require("./erpnext/doctypes/servicecase");
|
|
33
|
-
const ServiceportalProductConfiguration_1 = require("./erpnext/model/ServiceportalProductConfiguration");
|
|
34
|
-
const ShippingLabel_1 = require("./erpnext/model/ShippingLabel");
|
|
35
|
-
const ServicecaseReason_1 = require("./erpnext/model/ServicecaseReason");
|
|
36
|
-
const ServicecaseSolution_1 = require("./erpnext/model/ServicecaseSolution");
|
|
37
|
-
const InternalReasons_1 = require("./erpnext/model/InternalReasons");
|
|
38
|
-
const File_1 = require("./erpnext/model/File");
|
|
39
|
-
const ConsolidatedCustomsInvoice_1 = require("./erpnext/model/ConsolidatedCustomsInvoice");
|
|
40
42
|
class ERPNextQueueClient {
|
|
41
43
|
/**
|
|
42
44
|
* @description Provide either a temporal client or connection details to create a new client
|
|
@@ -69,6 +71,8 @@ class ERPNextQueueClient {
|
|
|
69
71
|
this.supplier = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Supplier", Supplier_1.Supplier);
|
|
70
72
|
this.paymentEntry = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Payment Entry", PaymentEntry_1.PaymentEntry);
|
|
71
73
|
this.stockReconciliation = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Stock Reconciliation", StockReconciliation_1.StockReconciliation);
|
|
74
|
+
this.salesOrder = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Sales Order", SalesOrder_1.SalesOrder);
|
|
75
|
+
this.salesInvoice = new salesInvoice_1.ERPNextSalesInvoice(this.temporalClient);
|
|
72
76
|
this.reports = new reports_1.ERPNextReports(this.temporalClient);
|
|
73
77
|
this.stock = new stock_1.ERPNextStock(this.temporalClient);
|
|
74
78
|
this.compliance = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Compliance", Compliance_1.Compliance);
|
|
@@ -79,8 +83,7 @@ class ERPNextQueueClient {
|
|
|
79
83
|
this.servicecaseSolution = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Servicecase Solution", ServicecaseSolution_1.ServiceCaseSolution);
|
|
80
84
|
this.internalReason = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Internal Reason", InternalReasons_1.InternalReason);
|
|
81
85
|
this.shippingLabel = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Shipping Label", ShippingLabel_1.ShippingLabel);
|
|
82
|
-
this.
|
|
83
|
-
new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Consolidated Customs Invoice", ConsolidatedCustomsInvoice_1.ConsolidatedCustomsInvoice);
|
|
86
|
+
this.tags = new tags_1.ERPNextTags(this.temporalClient);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
exports.ERPNextQueueClient = ERPNextQueueClient;
|
|
@@ -89,3 +92,12 @@ Object.defineProperty(exports, "ERPNextMethodResponse", { enumerable: true, get:
|
|
|
89
92
|
Object.defineProperty(exports, "ERPNextResourceResponse", { enumerable: true, get: function () { return ERPNextResponse_1.ERPNextResourceResponse; } });
|
|
90
93
|
var zodUtils_1 = require("./utils/zodUtils");
|
|
91
94
|
Object.defineProperty(exports, "pickFromSchema", { enumerable: true, get: function () { return zodUtils_1.pickFromSchema; } });
|
|
95
|
+
var DocTypeHelpers_1 = require("./erpnext/model/DocTypeHelpers");
|
|
96
|
+
Object.defineProperty(exports, "AugmentChildTableArrays", { enumerable: true, get: function () { return DocTypeHelpers_1.AugmentChildTableArrays; } });
|
|
97
|
+
Object.defineProperty(exports, "CreateChildTableEntrySchema", { enumerable: true, get: function () { return DocTypeHelpers_1.CreateChildTableEntrySchema; } });
|
|
98
|
+
Object.defineProperty(exports, "DocTypeList", { enumerable: true, get: function () { return DocTypeHelpers_1.DocTypeList; } });
|
|
99
|
+
Object.defineProperty(exports, "LoadDocumentWrapper", { enumerable: true, get: function () { return DocTypeHelpers_1.LoadDocumentWrapper; } });
|
|
100
|
+
var ERPNextDocTypeMeta_1 = require("./erpnext/model/ERPNextDocTypeMeta");
|
|
101
|
+
Object.defineProperty(exports, "DocTypeChildTableEntryMeta", { enumerable: true, get: function () { return ERPNextDocTypeMeta_1.DocTypeChildTableEntryMeta; } });
|
|
102
|
+
Object.defineProperty(exports, "DocTypeMeta", { enumerable: true, get: function () { return ERPNextDocTypeMeta_1.DocTypeMeta; } });
|
|
103
|
+
Object.defineProperty(exports, "DocTypeNested", { enumerable: true, get: function () { return ERPNextDocTypeMeta_1.DocTypeNested; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Type testing only - should not be in compiled code
|
|
3
|
+
// Use this to statically test types before build
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const _1 = require(".");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
const zod_1 = __importDefault(require("zod"));
|
|
20
|
+
const zodContextOptionals_1 = require("./utils/zodContextOptionals");
|
|
21
|
+
const Address_1 = require("./erpnext/model/Address");
|
|
22
|
+
describe("Type tests", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
console.log("THIS TEST IS RUN ON erp-test - Make sure the test instance ");
|
|
25
|
+
});
|
|
26
|
+
const erp = new _1.ERPNextQueueClient({
|
|
27
|
+
temporalCredentials: {
|
|
28
|
+
temporalHost: constants_1.constants.TEMPORAL_ERPNEXT_QUEUE_HOST,
|
|
29
|
+
temporalNamespace: constants_1.constants.TEMPORAL_ERPNEXT_QUEUE_NAMESPACE,
|
|
30
|
+
temporalCert: constants_1.constants.TEMPORAL_CRT,
|
|
31
|
+
temporalKey: constants_1.constants.TEMPORAL_KEY,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
test("Single item fetch", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
36
|
+
// We use expect-error to statically test negative cases in typescript
|
|
37
|
+
const items = yield erp.item.getList({ limit: 1 });
|
|
38
|
+
const item = yield erp.item.getById({ resourceId: items[0].name });
|
|
39
|
+
expect(item.name).toBeTypeOf("string");
|
|
40
|
+
expect(item.doctype).toBeTypeOf("string");
|
|
41
|
+
expect(item.description).toBeTypeOf("string");
|
|
42
|
+
expect((_a = item.barcodes.at(0)) === null || _a === void 0 ? void 0 : _a.idx).toBeTypeOf("number");
|
|
43
|
+
}));
|
|
44
|
+
test("Item List with field description", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f;
|
|
46
|
+
// get list with field defined
|
|
47
|
+
const itemsOnlyFieldDescription = yield erp.item.getList({
|
|
48
|
+
fields: ["description"],
|
|
49
|
+
limit: 10,
|
|
50
|
+
});
|
|
51
|
+
expect(
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
(_c = (_b = (_a = itemsOnlyFieldDescription.at(0)) === null || _a === void 0 ? void 0 : _a.barcodes) === null || _b === void 0 ? void 0 : _b.at(0)) === null || _c === void 0 ? void 0 : _c.idx).toBeUndefined();
|
|
54
|
+
expect((_d = itemsOnlyFieldDescription.at(0)) === null || _d === void 0 ? void 0 : _d.description).toBeTypeOf("string");
|
|
55
|
+
// @ts-expect-error
|
|
56
|
+
expect((_e = itemsOnlyFieldDescription.at(0)) === null || _e === void 0 ? void 0 : _e.name).toBeUndefined(); // name not valid here
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
expect((_f = itemsOnlyFieldDescription.at(0)) === null || _f === void 0 ? void 0 : _f.barcodes).toBeUndefined(); // barcodes not valid here
|
|
59
|
+
}));
|
|
60
|
+
test("Item List with default field 'name'", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
// get list without fields defined
|
|
63
|
+
const items2 = yield erp.item.getList({ limit: 10 });
|
|
64
|
+
expect((_a = items2.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
expect((_b = items2.at(0)) === null || _b === void 0 ? void 0 : _b.item_code).toBeUndefined(); // item_code not valid here
|
|
67
|
+
}));
|
|
68
|
+
test("Item List with all fields", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
// get list without fields defined
|
|
70
|
+
var _a, _b, _c, _d;
|
|
71
|
+
const itemsWithAllFields = yield erp.item.getList({
|
|
72
|
+
fields: ["*"],
|
|
73
|
+
limit: 10,
|
|
74
|
+
});
|
|
75
|
+
expect((_a = itemsWithAllFields.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
|
|
76
|
+
// @ts-expect-error
|
|
77
|
+
expect((_b = itemsWithAllFields.at(0)) === null || _b === void 0 ? void 0 : _b.doctype).toBeUndefined(); // doctype omitted in list entries
|
|
78
|
+
expect((_c = itemsWithAllFields.at(0)) === null || _c === void 0 ? void 0 : _c.item_code).toBeTypeOf("string");
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
expect((_d = itemsWithAllFields.at(0)) === null || _d === void 0 ? void 0 : _d.barcodes).toBeUndefined();
|
|
81
|
+
}));
|
|
82
|
+
test("Submittable DocType", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const dns = yield erp.deliveryNote.getList({ limit: 1 });
|
|
84
|
+
if (!dns[0])
|
|
85
|
+
throw new Error("No Delivery Notes found in test instance");
|
|
86
|
+
const dn = yield erp.deliveryNote.getById({
|
|
87
|
+
resourceId: dns[0].name,
|
|
88
|
+
});
|
|
89
|
+
dn.amended_from; // for static type analysis
|
|
90
|
+
}));
|
|
91
|
+
test("Get Address by Supplier", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
const sup = yield erp.supplier.getList({ limit: 1 });
|
|
93
|
+
const address = yield erp.address.getAddressesBySupplier(sup[0].name);
|
|
94
|
+
expect(address[0].city).toBeTypeOf("string");
|
|
95
|
+
}));
|
|
96
|
+
test("Item List with invalid field list", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
// don't execute, this is just for type testing statically
|
|
98
|
+
() => erp.item.getList({
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
fields: ["name", "barcode"],
|
|
101
|
+
limit: 10,
|
|
102
|
+
});
|
|
103
|
+
}));
|
|
104
|
+
test("Create with DocModel Metafields should fail", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
// DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
|
|
106
|
+
// We use expect-error to statically test negative cases in typescript
|
|
107
|
+
() => erp.item.create({
|
|
108
|
+
body: {
|
|
109
|
+
// @ts-expect-error
|
|
110
|
+
name: "TEST", // name and other metafields should not be set on create
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
() => erp.resourceRequest.create({
|
|
114
|
+
// @ts-expect-error - mandatory is missing, we expect an error here
|
|
115
|
+
body: {
|
|
116
|
+
optional: "string",
|
|
117
|
+
},
|
|
118
|
+
resourceName: "TEST",
|
|
119
|
+
resourceModel: zod_1.default.object({
|
|
120
|
+
mandatory: zod_1.default.string(),
|
|
121
|
+
optional: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
// should have no errors since the optional key is input-optional
|
|
125
|
+
() => erp.resourceRequest.create({
|
|
126
|
+
body: {
|
|
127
|
+
mandatory: "string",
|
|
128
|
+
},
|
|
129
|
+
resourceName: "TEST",
|
|
130
|
+
resourceModel: zod_1.default.object({
|
|
131
|
+
mandatory: zod_1.default.string(),
|
|
132
|
+
optional: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
() => erp.paymentEntry.create({
|
|
136
|
+
body: {
|
|
137
|
+
naming_series: "PAY-.#",
|
|
138
|
+
paid_amount: 12,
|
|
139
|
+
party: "test",
|
|
140
|
+
party_type: "Customer",
|
|
141
|
+
payment_type: "Receive",
|
|
142
|
+
reference_no: "REF",
|
|
143
|
+
reference_date: "2025-01-01",
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
() => erp.salesOrder.create({
|
|
147
|
+
// @ts-expect-error should not be empty
|
|
148
|
+
body: {},
|
|
149
|
+
});
|
|
150
|
+
}));
|
|
151
|
+
test("Static Types with Input Optional", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
+
// DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
|
|
153
|
+
// We use expect-error to statically test negative cases in typescript
|
|
154
|
+
const testModel = zod_1.default.object({
|
|
155
|
+
mandatory: zod_1.default.string(),
|
|
156
|
+
optionalInInput: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
|
|
157
|
+
});
|
|
158
|
+
const inputModel = (0, zodContextOptionals_1.ResourceInput)(testModel);
|
|
159
|
+
const testInputWrongType = {
|
|
160
|
+
mandatory: "TEST",
|
|
161
|
+
// @ts-expect-error because type is set incorrectly
|
|
162
|
+
optionalInInput: 1,
|
|
163
|
+
};
|
|
164
|
+
const testInputCorrect = {
|
|
165
|
+
mandatory: "TEST",
|
|
166
|
+
};
|
|
167
|
+
// @ts-expect-error because output should contain optionalInInput
|
|
168
|
+
const testOutput = {
|
|
169
|
+
mandatory: "TEST",
|
|
170
|
+
};
|
|
171
|
+
}));
|
|
172
|
+
test("Static Types with Nested Array Input Optional", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
// DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
|
|
174
|
+
// We use expect-error to statically test negative cases in typescript
|
|
175
|
+
const testModel = zod_1.default.object({
|
|
176
|
+
mandatory: zod_1.default.string(),
|
|
177
|
+
subarray: zod_1.default.array(zod_1.default.object({
|
|
178
|
+
mandatoryElement: zod_1.default.string(),
|
|
179
|
+
inputOptionalSubarrayElement: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
|
|
180
|
+
})),
|
|
181
|
+
});
|
|
182
|
+
const inputModel = (0, zodContextOptionals_1.ResourceInput)(testModel);
|
|
183
|
+
const testInputWrongType = {
|
|
184
|
+
mandatory: "TEST",
|
|
185
|
+
subarray: [
|
|
186
|
+
{
|
|
187
|
+
mandatoryElement: "test",
|
|
188
|
+
// @ts-expect-error because type is set incorrectly
|
|
189
|
+
inputOptionalSubarrayElement: 1,
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
const testInputCorrect = {
|
|
194
|
+
mandatory: "TEST",
|
|
195
|
+
subarray: [
|
|
196
|
+
{
|
|
197
|
+
mandatoryElement: "test",
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
const testOutput = {
|
|
202
|
+
mandatory: "TEST",
|
|
203
|
+
subarray: [
|
|
204
|
+
// @ts-expect-error because output should contain inputOptionalSubarrayElement
|
|
205
|
+
{
|
|
206
|
+
mandatoryElement: "test",
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
};
|
|
210
|
+
}));
|
|
211
|
+
test("Input for updateById function", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
212
|
+
// This static type test ensures, that Input as inferred here
|
|
213
|
+
// conformes to the expected input type defined in doctypeResourceRequest -> updateById()
|
|
214
|
+
const AddressInput = (0, zodContextOptionals_1.ResourceInput)(Address_1.Address);
|
|
215
|
+
const typedInputBody = {
|
|
216
|
+
address_line1: "test",
|
|
217
|
+
address_type: "TEST",
|
|
218
|
+
city: "CITY",
|
|
219
|
+
country: "Country",
|
|
220
|
+
pincode: "1234",
|
|
221
|
+
};
|
|
222
|
+
yield erp.address.updateById({
|
|
223
|
+
resourceId: "TEST",
|
|
224
|
+
body: typedInputBody,
|
|
225
|
+
});
|
|
226
|
+
}));
|
|
227
|
+
}));
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type Prettify<T> = {
|
|
2
|
+
[K in keyof T]: T[K];
|
|
3
|
+
} & {};
|
|
1
4
|
export declare function addDays(date: string | number | Date, days: number): Date;
|
|
2
5
|
export declare function addMinutes(date: Date, minutes: number): Date;
|
|
3
6
|
export declare function timeout(ms: number): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyZodObject, z, ZodArray, ZodObject, ZodRawShape } from "zod";
|
|
2
|
+
type MarkedInputOptional<T extends z.ZodTypeAny> = T & {
|
|
3
|
+
__optionalForInput: true;
|
|
4
|
+
};
|
|
5
|
+
export declare function optionalForInput<T extends z.ZodTypeAny>(schema: T): MarkedInputOptional<T>;
|
|
6
|
+
type TransformInnerShape<S extends ZodRawShape> = {
|
|
7
|
+
[P in keyof S]: S[P] extends MarkedInputOptional<infer U> ? z.ZodOptional<U> : S[P];
|
|
8
|
+
};
|
|
9
|
+
type TransformOneLevel<V> = V extends MarkedInputOptional<infer U> ? z.ZodOptional<U> : V extends ZodObject<infer S extends ZodRawShape> ? ZodObject<TransformInnerShape<S>> : V extends ZodArray<infer Elem> ? Elem extends ZodObject<infer S2 extends ZodRawShape> ? ZodArray<ZodObject<TransformInnerShape<S2>>> : V : V;
|
|
10
|
+
export type ResourceInputType<T extends AnyZodObject> = ZodObject<{
|
|
11
|
+
[K in keyof T["shape"]]: TransformOneLevel<T["shape"][K]>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function ResourceInput<T extends ZodRawShape>(schema: z.ZodObject<T>): ResourceInputType<z.ZodObject<T>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.optionalForInput = optionalForInput;
|
|
4
|
+
exports.ResourceInput = ResourceInput;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
// Helper to mark a field as optional for input
|
|
7
|
+
function optionalForInput(schema) {
|
|
8
|
+
return Object.assign(schema, {
|
|
9
|
+
__optionalForInput: true,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
// Helper to check if field is marked
|
|
13
|
+
function isMarkedOptionalForInput(schema) {
|
|
14
|
+
return "__optionalForInput" in schema && schema.__optionalForInput === true;
|
|
15
|
+
}
|
|
16
|
+
// schema transformation
|
|
17
|
+
function ResourceInput(schema) {
|
|
18
|
+
const shape = schema.shape;
|
|
19
|
+
function makeMarkedKeysOptional(shape) {
|
|
20
|
+
const newShape = {};
|
|
21
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
22
|
+
if (isMarkedOptionalForInput(value)) {
|
|
23
|
+
newShape[key] = value.optional();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
newShape[key] = value;
|
|
27
|
+
}
|
|
28
|
+
// Recurse one level into nested objects to apply the same optionalization
|
|
29
|
+
if (value instanceof zod_1.z.ZodObject) {
|
|
30
|
+
const innerShape = value.shape;
|
|
31
|
+
newShape[key] = makeMarkedKeysOptional(innerShape);
|
|
32
|
+
}
|
|
33
|
+
else if (value instanceof zod_1.ZodArray) {
|
|
34
|
+
const arrayElementShape = value.element
|
|
35
|
+
.shape;
|
|
36
|
+
newShape[key] = zod_1.z.array(makeMarkedKeysOptional(arrayElementShape));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return newShape;
|
|
40
|
+
}
|
|
41
|
+
return zod_1.z.object(makeMarkedKeysOptional(shape));
|
|
42
|
+
}
|
package/dist/utils/zodUtils.js
CHANGED
|
@@ -8,6 +8,7 @@ const logger_1 = require("./logger");
|
|
|
8
8
|
function validateData(data, ValidationModel) {
|
|
9
9
|
if (!ValidationModel.description)
|
|
10
10
|
throw new Error("ValidationModel.description is required");
|
|
11
|
+
// writeFileSync("test.json", JSON.stringify(data, null, 2));
|
|
11
12
|
const validationResult = ValidationModel.safeParse(data);
|
|
12
13
|
if (!validationResult.success) {
|
|
13
14
|
const errorObject = {
|
|
@@ -17,11 +18,11 @@ function validateData(data, ValidationModel) {
|
|
|
17
18
|
? data
|
|
18
19
|
: "set DEBUG_MODE to true to see the input",
|
|
19
20
|
};
|
|
21
|
+
logger_1.lg.error(errorObject);
|
|
20
22
|
if (data &&
|
|
21
23
|
typeof data === "object" &&
|
|
22
24
|
"message" in data &&
|
|
23
25
|
typeof data.message === "string") {
|
|
24
|
-
logger_1.lg.error(errorObject);
|
|
25
26
|
throw new Error(data.message);
|
|
26
27
|
}
|
|
27
28
|
throw errorObject;
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"winston": "^3.15.0",
|
|
26
26
|
"zod": "3.25.76"
|
|
27
27
|
},
|
|
28
|
-
"version": "
|
|
28
|
+
"version": "2.0.0-beta.0",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/crypto-js": "^4.2.2",
|
|
31
31
|
"@types/lodash": "^4.17.13",
|
|
@@ -34,4 +34,4 @@
|
|
|
34
34
|
"typescript": "^5.6.3",
|
|
35
35
|
"vitest": "^2.1.8"
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
}
|