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
@@ -1,13 +1,4 @@
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ERPNextResourceRequest = void 0;
13
4
  const zod_1 = require("zod");
@@ -18,158 +9,159 @@ const DocTypeHelpers_1 = require("./model/DocTypeHelpers");
18
9
  const ERPNextResponse_1 = require("./model/ERPNextResponse");
19
10
  const zodContextOptionals_1 = require("../utils/zodContextOptionals");
20
11
  class ERPNextResourceRequest {
12
+ temporalClient;
21
13
  constructor(temporalClient) {
22
- this.getParams = (fields, filters, asDict, params) => {
23
- const fieldsParams = fields
24
- ? { fields: `[${fields.map((fi) => `"${fi}"`).join(",")}]` }
25
- : {};
26
- const filtersParams = filters
27
- ? {
28
- filters: `[${filters
29
- .map((f) => `[${f.map((fi) => typeof fi === "string" ? `"${fi}"` : `["${fi.join('","')}"]`)}]`)
30
- .join(",")}]`,
31
- }
32
- : {};
33
- const asDictParams = asDict === false ? { as_dict: "False" } : {};
34
- const allParams = Object.assign(Object.assign(Object.assign(Object.assign({}, fieldsParams), filtersParams), asDictParams), params);
35
- return allParams;
36
- };
37
14
  this.temporalClient = temporalClient;
38
15
  }
39
- getList(_a) {
40
- return __awaiter(this, arguments, void 0, function* ({ resourceName, fields, filters, resourceModel, skip, limit, priority = 5, asDict, params, }) {
41
- if (resourceModel && !resourceModel.description)
42
- throw new Error("Resource model must have a description");
43
- const erpNextFields = (fields === null || fields === void 0 ? void 0 : fields.length)
44
- ? fields
45
- : ["name"]; // default field is name
46
- const schema = asDict === false
47
- ? zod_1.z
48
- .object({
49
- data: zod_1.z.array(zod_1.z.array(zod_1.z.string())),
50
- })
51
- .describe(`${(resourceModel === null || resourceModel === void 0 ? void 0 : resourceModel.description)
52
- ? (resourceModel === null || resourceModel === void 0 ? void 0 : resourceModel.description) + " "
53
- : ""}List with fields ${JSON.stringify(erpNextFields)} as dict = false`)
54
- : resourceModel
55
- ? (fields === null || fields === void 0 ? void 0 : fields[0]) === "*"
56
- ? zod_1.z
57
- .object({ data: zod_1.z.array((0, DocTypeHelpers_1.DocModelListEntry)(resourceModel)) })
58
- .describe(`${resourceName} List with all fields`)
59
- : zod_1.z
60
- .object({
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
- )),
63
- })
64
- .describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields.filter((f) => f !== "*"))}`)
65
- : zod_1.z.any().describe("Any response");
66
- const defaultPaginationSize = 500;
67
- let loopLimit = defaultPaginationSize;
68
- let loopSkip = 0;
69
- let results = [];
70
- let currentResult = [];
71
- // when skip or limit are defined, don't loop automatically.
72
- const autoPaginate = skip || limit ? false : true;
73
- if (autoPaginate)
74
- logger_1.lg.info("AUTO PAGINATE");
75
- do {
76
- // use limit & skip whenever it is directly provided. In other cases use loopLimit & loopSkip to remove pagination
77
- const paramsString = (0, utils_1.paramsToString)(Object.assign(Object.assign(Object.assign({}, this.getParams(erpNextFields, filters, asDict, params)), (limit === undefined && !autoPaginate
16
+ getParams = (fields, filters, asDict, params) => {
17
+ const fieldsParams = fields
18
+ ? { fields: `[${fields.map((fi) => `"${fi}"`).join(",")}]` }
19
+ : {};
20
+ const filtersParams = filters
21
+ ? {
22
+ filters: `[${filters
23
+ .map((f) => `[${f.map((fi) => typeof fi === "string" ? `"${fi}"` : `["${fi.join('","')}"]`)}]`)
24
+ .join(",")}]`,
25
+ }
26
+ : {};
27
+ const asDictParams = asDict === false ? { as_dict: "False" } : {};
28
+ const allParams = {
29
+ ...fieldsParams,
30
+ ...filtersParams,
31
+ ...asDictParams,
32
+ ...params,
33
+ };
34
+ return allParams;
35
+ };
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
+ const erpNextFields = fields?.length
40
+ ? fields
41
+ : ["name"]; // default field is name
42
+ const schema = asDict === false
43
+ ? zod_1.z
44
+ .object({
45
+ data: zod_1.z.array(zod_1.z.array(zod_1.z.string())),
46
+ })
47
+ .describe(`${resourceModel?.description
48
+ ? resourceModel?.description + " "
49
+ : ""}List with fields ${JSON.stringify(erpNextFields)} as dict = false`)
50
+ : resourceModel
51
+ ? fields?.[0] === "*"
52
+ ? zod_1.z
53
+ .object({ data: zod_1.z.array((0, DocTypeHelpers_1.DocModelListEntry)(resourceModel)) })
54
+ .describe(`${resourceName} List with all fields`)
55
+ : zod_1.z
56
+ .object({
57
+ 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
+ )),
59
+ })
60
+ .describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields.filter((f) => f !== "*"))}`)
61
+ : zod_1.z.any().describe("Any response");
62
+ const defaultPaginationSize = 500;
63
+ let loopLimit = defaultPaginationSize;
64
+ let loopSkip = 0;
65
+ let results = [];
66
+ let currentResult = [];
67
+ // when skip or limit are defined, don't loop automatically.
68
+ const autoPaginate = skip || limit ? false : true;
69
+ if (autoPaginate)
70
+ logger_1.lg.info("AUTO PAGINATE");
71
+ do {
72
+ // use limit & skip whenever it is directly provided. In other cases use loopLimit & loopSkip to remove pagination
73
+ const paramsString = (0, utils_1.paramsToString)({
74
+ ...this.getParams(erpNextFields, filters, asDict, params),
75
+ ...(limit === undefined && !autoPaginate
78
76
  ? {}
79
- : { limit: String(limit !== null && limit !== void 0 ? limit : loopLimit) })), (skip === undefined && !autoPaginate
77
+ : { limit: String(limit ?? loopLimit) }),
78
+ ...(skip === undefined && !autoPaginate
80
79
  ? {}
81
- : { limit_start: String(skip !== null && skip !== void 0 ? skip : loopSkip) })));
82
- const result = yield this.temporalClient.executeERPNextRequestWorkflow(`GET-${resourceName.toLowerCase()}-List`, {
83
- requestMethod: "GET",
84
- resourceName,
85
- responseValidationModel: schema,
86
- params: paramsString,
87
- }, "erpnext", priority);
88
- currentResult = result.data;
89
- results = [...results, ...currentResult];
90
- loopSkip = loopSkip + loopLimit;
91
- } while (autoPaginate && currentResult.length);
92
- return results;
93
- });
94
- }
95
- getById(_a) {
96
- return __awaiter(this, arguments, void 0, function* ({ resourceName, resourceId, resourceModel, priority = 5, }) {
97
- if (resourceModel && !resourceModel.description)
98
- throw new Error("Resource model must have a description");
99
- if (!resourceId)
100
- throw new Error("Resource id is required");
101
- const result = yield this.temporalClient
102
- .executeERPNextRequestWorkflow(`GET-${resourceName}-${resourceId}`, {
103
- requestMethod: "GET",
104
- resourceName,
105
- resourceId,
106
- responseValidationModel: resourceModel
107
- ? zod_1.z
108
- .object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) })
109
- .describe(resourceName + " Response")
110
- : undefined,
111
- }, "erpnext", priority)
112
- .catch((err) => {
113
- if (err.message.includes("Error 404")) {
114
- logger_1.lg.error(`Resource ${resourceName} with id ${resourceId} not found`);
115
- return;
116
- }
117
- throw err;
80
+ : { limit_start: String(skip ?? loopSkip) }),
118
81
  });
119
- return result === null || result === void 0 ? void 0 : result.data;
120
- });
121
- }
122
- updateById(_a) {
123
- return __awaiter(this, arguments, void 0, function* ({ resourceName, resourceId, inputValidationModel, resourceModel, body, priority = 5, }) {
124
- // accept partial input while enforcing allowed keys
125
- const partialInputValidationModel = inputValidationModel && inputValidationModel instanceof zod_1.ZodObject
126
- ? inputValidationModel.partial().strict()
127
- : inputValidationModel;
128
- const result = yield this.temporalClient.executeERPNextRequestWorkflow(`PUT-${resourceName}-${resourceId}`, {
129
- requestMethod: "PUT",
130
- resourceId,
82
+ const result = await this.temporalClient.executeERPNextRequestWorkflow(`GET-${resourceName.toLowerCase()}-List`, {
83
+ requestMethod: "GET",
131
84
  resourceName,
132
- inputValidationModel: partialInputValidationModel,
133
- responseValidationModel: resourceModel
134
- ? zod_1.z.object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) }).describe(resourceName)
135
- : undefined,
136
- body,
85
+ responseValidationModel: schema,
86
+ params: paramsString,
137
87
  }, "erpnext", priority);
138
- return result.data;
139
- });
88
+ currentResult = result.data;
89
+ results = [...results, ...currentResult];
90
+ loopSkip = loopSkip + loopLimit;
91
+ } while (autoPaginate && currentResult.length);
92
+ return results;
140
93
  }
141
- create(_a) {
142
- return __awaiter(this, arguments, void 0, function* ({ resourceName, inputValidationModel, resourceModel, body, params, priority = 5, }) {
143
- if (resourceModel && !resourceModel.description)
144
- throw new Error("Resource model must have a description");
145
- const result = yield this.temporalClient.executeERPNextRequestWorkflow(`POST-${resourceName}`, {
146
- requestMethod: "POST",
147
- resourceName,
148
- inputValidationModel: inputValidationModel !== null && inputValidationModel !== void 0 ? inputValidationModel : (resourceModel ? (0, zodContextOptionals_1.ResourceInput)(resourceModel) : undefined),
149
- responseValidationModel: resourceModel
150
- ? zod_1.z
151
- .object({
152
- data: (0, DocTypeHelpers_1.DocModel)(resourceModel),
153
- })
154
- .describe(resourceModel.description)
155
- : undefined,
156
- params: (0, utils_1.paramsToString)(params),
157
- body,
158
- }, "erpnext", priority);
159
- return result.data;
94
+ async getById({ resourceName, resourceId, resourceModel, priority = 5, }) {
95
+ if (resourceModel && !resourceModel.description)
96
+ throw new Error("Resource model must have a description");
97
+ if (!resourceId)
98
+ throw new Error("Resource id is required");
99
+ const result = await this.temporalClient
100
+ .executeERPNextRequestWorkflow(`GET-${resourceName}-${resourceId}`, {
101
+ requestMethod: "GET",
102
+ resourceName,
103
+ resourceId,
104
+ responseValidationModel: resourceModel
105
+ ? zod_1.z
106
+ .object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) })
107
+ .describe(resourceName + " Response")
108
+ : undefined,
109
+ }, "erpnext", priority)
110
+ .catch((err) => {
111
+ if (err.message.includes("Error 404")) {
112
+ logger_1.lg.error(`Resource ${resourceName} with id ${resourceId} not found`);
113
+ return;
114
+ }
115
+ throw err;
160
116
  });
117
+ return result?.data;
161
118
  }
162
- deleteById(_a) {
163
- return __awaiter(this, arguments, void 0, function* ({ resourceName, resourceId, resourceModel, priority = 5, }) {
164
- if (resourceModel && !resourceModel.description)
165
- throw new Error("Resource model must have a description");
166
- return yield this.temporalClient.executeERPNextRequestWorkflow(`DELETE-${resourceName}`, {
167
- requestMethod: "DELETE",
168
- resourceName,
169
- resourceId,
170
- responseValidationModel: ERPNextResponse_1.DeleteResponseModel,
171
- }, "erpnext", priority);
172
- });
119
+ async updateById({ resourceName, resourceId, inputValidationModel, resourceModel, body, priority = 5, }) {
120
+ // accept partial input while enforcing allowed keys
121
+ const partialInputValidationModel = inputValidationModel && inputValidationModel instanceof zod_1.ZodObject
122
+ ? inputValidationModel.partial().strict()
123
+ : inputValidationModel;
124
+ const result = await this.temporalClient.executeERPNextRequestWorkflow(`PUT-${resourceName}-${resourceId}`, {
125
+ requestMethod: "PUT",
126
+ resourceId,
127
+ resourceName,
128
+ inputValidationModel: partialInputValidationModel,
129
+ responseValidationModel: resourceModel
130
+ ? zod_1.z.object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) }).describe(resourceName)
131
+ : undefined,
132
+ body,
133
+ }, "erpnext", priority);
134
+ return result.data;
135
+ }
136
+ 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
+ const result = await this.temporalClient.executeERPNextRequestWorkflow(`POST-${resourceName}`, {
140
+ requestMethod: "POST",
141
+ resourceName,
142
+ inputValidationModel: inputValidationModel ??
143
+ (resourceModel ? (0, zodContextOptionals_1.ResourceInput)(resourceModel) : undefined),
144
+ responseValidationModel: resourceModel
145
+ ? zod_1.z
146
+ .object({
147
+ data: (0, DocTypeHelpers_1.DocModel)(resourceModel),
148
+ })
149
+ .describe(resourceModel.description)
150
+ : undefined,
151
+ params: (0, utils_1.paramsToString)(params),
152
+ body,
153
+ }, "erpnext", priority);
154
+ return result.data;
155
+ }
156
+ async deleteById({ resourceName, resourceId, resourceModel, priority = 5, }) {
157
+ if (resourceModel && !resourceModel.description)
158
+ throw new Error("Resource model must have a description");
159
+ return await this.temporalClient.executeERPNextRequestWorkflow(`DELETE-${resourceName}`, {
160
+ requestMethod: "DELETE",
161
+ resourceName,
162
+ resourceId,
163
+ responseValidationModel: ERPNextResponse_1.DeleteResponseModel,
164
+ }, "erpnext", priority);
173
165
  }
174
166
  }
175
167
  exports.ERPNextResourceRequest = ERPNextResourceRequest;
package/dist/index.js CHANGED
@@ -44,13 +44,50 @@ const Waitlist_1 = require("./erpnext/model/Waitlist");
44
44
  const reports_1 = require("./erpnext/reports");
45
45
  const resourceRequest_1 = require("./erpnext/resourceRequest");
46
46
  class ERPNextQueueClient {
47
+ temporalClient;
48
+ credentials;
49
+ resourceRequest;
50
+ methodRequest;
51
+ account;
52
+ country;
53
+ address;
54
+ contact;
55
+ customer;
56
+ deliveryNote;
57
+ fileRequests;
58
+ shipment;
59
+ productBundle;
60
+ shippingProvider;
61
+ item;
62
+ purchaseOrder;
63
+ purchaseReceipt;
64
+ purchaseInvoice;
65
+ waitlist;
66
+ stockEntry;
67
+ supplier;
68
+ paymentEntry;
69
+ stockReconciliation;
70
+ stock;
71
+ reports;
72
+ compliance;
73
+ partList;
74
+ salesOrder;
75
+ salesInvoice;
76
+ servicecase;
77
+ serviceportalProductConfiguration;
78
+ servicecaseReason;
79
+ servicecaseSolution;
80
+ internalReason;
81
+ shippingLabel;
82
+ file;
83
+ itemTaxTemplate;
84
+ taxCategory;
85
+ tags;
86
+ consolidatedCustomsInvoice;
47
87
  /**
48
88
  * @description Provide either a temporal client or connection details to create a new client
49
89
  */
50
90
  constructor(options) {
51
- this.utils = {
52
- decryptFromErpNext: (encryptedString) => (0, decryptFromErpNext_server_1.decryptFromErpNext)(this.credentials, encryptedString),
53
- };
54
91
  if (options.erpnextCredentials)
55
92
  this.credentials = options.erpnextCredentials;
56
93
  this.temporalClient = new client_1.TemporalClient(options.temporalCredentials);
@@ -94,6 +131,9 @@ class ERPNextQueueClient {
94
131
  this.tags = new tags_1.ERPNextTags(this.temporalClient);
95
132
  this.consolidatedCustomsInvoice = new consolidatedCustomsInvoice_1.ERPNextConsolidatedCustomsInvoice(this.temporalClient);
96
133
  }
134
+ utils = {
135
+ decryptFromErpNext: (encryptedString) => (0, decryptFromErpNext_server_1.decryptFromErpNext)(this.credentials, encryptedString),
136
+ };
97
137
  }
98
138
  exports.ERPNextQueueClient = ERPNextQueueClient;
99
139
  var ERPNextResponse_1 = require("./erpnext/model/ERPNextResponse");
@@ -1,13 +1,4 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -20,7 +11,7 @@ const zodContextOptionals_1 = require("./utils/zodContextOptionals");
20
11
  const Item_1 = require("./erpnext/model/Item");
21
12
  // Most tests are wrapped in async function blocks so they are declared statically but not run as tests.
22
13
  // If we wanted to run the tests, a mocking system would need to be implemented.
23
- describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", () => __awaiter(void 0, void 0, void 0, function* () {
14
+ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", async () => {
24
15
  const erp = new _1.ERPNextQueueClient({
25
16
  temporalCredentials: {
26
17
  temporalHost: constants_1.constants.TEMPORAL_HOST,
@@ -29,21 +20,19 @@ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", ()
29
20
  temporalKey: constants_1.constants.TEMPORAL_KEY,
30
21
  },
31
22
  });
32
- test("Single item fetch", () => __awaiter(void 0, void 0, void 0, function* () {
23
+ test("Single item fetch", async () => {
33
24
  // We use expect-error to statically test negative cases in typescript
34
- () => __awaiter(void 0, void 0, void 0, function* () {
35
- var _a;
36
- const items = yield erp.item.getList({ limit: 1 });
37
- const item = yield erp.item.getById({ resourceId: items[0].name });
38
- expect(item === null || item === void 0 ? void 0 : item.name).toBeTypeOf("string");
39
- expect(item === null || item === void 0 ? void 0 : item.doctype).toBeTypeOf("string");
40
- expect(item === null || item === void 0 ? void 0 : item.description).toBeTypeOf("string");
41
- expect((_a = item === null || item === void 0 ? void 0 : item.barcodes.at(0)) === null || _a === void 0 ? void 0 : _a.idx).toBeTypeOf("number");
42
- });
43
- }));
44
- test("List with aliases", () => __awaiter(void 0, void 0, void 0, function* () {
45
- var _a, _b, _c;
46
- const items = yield erp.resourceRequest.getList({
25
+ async () => {
26
+ const items = await erp.item.getList({ limit: 1 });
27
+ const item = await erp.item.getById({ resourceId: items[0].name });
28
+ expect(item?.name).toBeTypeOf("string");
29
+ expect(item?.doctype).toBeTypeOf("string");
30
+ expect(item?.description).toBeTypeOf("string");
31
+ expect(item?.barcodes.at(0)?.idx).toBeTypeOf("number");
32
+ };
33
+ });
34
+ test("List with aliases", async () => {
35
+ const items = await erp.resourceRequest.getList({
47
36
  resourceName: "Item",
48
37
  resourceModel: Item_1.Item.merge(zod_1.default.object({
49
38
  "`tabItem Supplier`.supplier as supplier": zod_1.default
@@ -59,81 +48,78 @@ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", ()
59
48
  "item_name as item_title",
60
49
  ],
61
50
  });
62
- expect((_a = items.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
63
- expect((_b = items.at(0)) === null || _b === void 0 ? void 0 : _b.supplier).toBeTypeOf("string");
64
- expect((_c = items.at(0)) === null || _c === void 0 ? void 0 : _c.item_title).toBeTypeOf("string");
65
- }));
66
- test("Item List with field description", () => __awaiter(void 0, void 0, void 0, function* () {
67
- () => __awaiter(void 0, void 0, void 0, function* () {
68
- var _a, _b, _c, _d, _e, _f;
51
+ expect(items.at(0)?.name).toBeTypeOf("string");
52
+ expect(items.at(0)?.supplier).toBeTypeOf("string");
53
+ expect(items.at(0)?.item_title).toBeTypeOf("string");
54
+ });
55
+ test("Item List with field description", async () => {
56
+ async () => {
69
57
  // get list with field defined
70
- const itemsOnlyFieldDescription = yield erp.item.getList({
58
+ const itemsOnlyFieldDescription = await erp.item.getList({
71
59
  fields: ["description"],
72
60
  limit: 10,
73
61
  });
74
62
  expect(
75
63
  // @ts-expect-error
76
- (_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();
77
- expect((_d = itemsOnlyFieldDescription.at(0)) === null || _d === void 0 ? void 0 : _d.description).toBeTypeOf("string");
64
+ itemsOnlyFieldDescription.at(0)?.barcodes?.at(0)?.idx).toBeUndefined();
65
+ expect(itemsOnlyFieldDescription.at(0)?.description).toBeTypeOf("string");
78
66
  // @ts-expect-error
79
- expect((_e = itemsOnlyFieldDescription.at(0)) === null || _e === void 0 ? void 0 : _e.name).toBeUndefined(); // name not valid here
67
+ expect(itemsOnlyFieldDescription.at(0)?.name).toBeUndefined(); // name not valid here
80
68
  // @ts-expect-error
81
- expect((_f = itemsOnlyFieldDescription.at(0)) === null || _f === void 0 ? void 0 : _f.barcodes).toBeUndefined(); // barcodes not valid here}
82
- });
83
- }));
84
- test("Item List with default field 'name'", () => __awaiter(void 0, void 0, void 0, function* () {
85
- () => __awaiter(void 0, void 0, void 0, function* () {
86
- var _a, _b;
69
+ expect(itemsOnlyFieldDescription.at(0)?.barcodes).toBeUndefined(); // barcodes not valid here}
70
+ };
71
+ });
72
+ test("Item List with default field 'name'", async () => {
73
+ async () => {
87
74
  // get list without fields defined
88
- const items2 = yield erp.item.getList({ limit: 10 });
89
- expect((_a = items2.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
75
+ const items2 = await erp.item.getList({ limit: 10 });
76
+ expect(items2.at(0)?.name).toBeTypeOf("string");
90
77
  // @ts-expect-error
91
- expect((_b = items2.at(0)) === null || _b === void 0 ? void 0 : _b.item_code).toBeUndefined(); // item_code not valid here
92
- });
93
- }));
94
- test("Item List with all fields", () => __awaiter(void 0, void 0, void 0, function* () {
95
- () => __awaiter(void 0, void 0, void 0, function* () {
96
- var _a, _b, _c, _d;
78
+ expect(items2.at(0)?.item_code).toBeUndefined(); // item_code not valid here
79
+ };
80
+ });
81
+ test("Item List with all fields", async () => {
82
+ async () => {
97
83
  // get list without fields defined
98
- const itemsWithAllFields = yield erp.item.getList({
84
+ const itemsWithAllFields = await erp.item.getList({
99
85
  fields: ["*"],
100
86
  limit: 10,
101
87
  });
102
- expect((_a = itemsWithAllFields.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
88
+ expect(itemsWithAllFields.at(0)?.name).toBeTypeOf("string");
103
89
  // @ts-expect-error
104
- expect((_b = itemsWithAllFields.at(0)) === null || _b === void 0 ? void 0 : _b.doctype).toBeUndefined(); // doctype omitted in list entries
105
- expect((_c = itemsWithAllFields.at(0)) === null || _c === void 0 ? void 0 : _c.item_code).toBeTypeOf("string");
90
+ expect(itemsWithAllFields.at(0)?.doctype).toBeUndefined(); // doctype omitted in list entries
91
+ expect(itemsWithAllFields.at(0)?.item_code).toBeTypeOf("string");
106
92
  // @ts-expect-error
107
- expect((_d = itemsWithAllFields.at(0)) === null || _d === void 0 ? void 0 : _d.barcodes).toBeUndefined();
108
- });
109
- }));
110
- test("Submittable DocType", () => __awaiter(void 0, void 0, void 0, function* () {
111
- () => __awaiter(void 0, void 0, void 0, function* () {
112
- const dns = yield erp.deliveryNote.getList({ limit: 1 });
93
+ expect(itemsWithAllFields.at(0)?.barcodes).toBeUndefined();
94
+ };
95
+ });
96
+ test("Submittable DocType", async () => {
97
+ async () => {
98
+ const dns = await erp.deliveryNote.getList({ limit: 1 });
113
99
  if (!dns[0])
114
100
  throw new Error("No Delivery Notes found in test instance");
115
- const dn = yield erp.deliveryNote.getById({
101
+ const dn = await erp.deliveryNote.getById({
116
102
  resourceId: dns[0].name,
117
103
  });
118
- dn === null || dn === void 0 ? void 0 : dn.amended_from; // for static type analysis}
119
- });
120
- }));
121
- test("Get Address by Supplier", () => __awaiter(void 0, void 0, void 0, function* () {
122
- () => __awaiter(void 0, void 0, void 0, function* () {
123
- const sup = yield erp.supplier.getList({ limit: 1 });
124
- const address = yield erp.address.getAddressesBySupplier(sup[0].name);
104
+ dn?.amended_from; // for static type analysis}
105
+ };
106
+ });
107
+ test("Get Address by Supplier", async () => {
108
+ async () => {
109
+ const sup = await erp.supplier.getList({ limit: 1 });
110
+ const address = await erp.address.getAddressesBySupplier(sup[0].name);
125
111
  expect(address[0].city).toBeTypeOf("string");
126
- });
127
- }));
128
- test("Item List with invalid field list", () => __awaiter(void 0, void 0, void 0, function* () {
112
+ };
113
+ });
114
+ test("Item List with invalid field list", async () => {
129
115
  // don't execute, this is just for type testing statically
130
116
  () => erp.item.getList({
131
117
  // @ts-expect-error
132
118
  fields: ["name", "barcode"],
133
119
  limit: 10,
134
120
  });
135
- }));
136
- test("Create with DocModel Metafields should fail", () => __awaiter(void 0, void 0, void 0, function* () {
121
+ });
122
+ test("Create with DocModel Metafields should fail", async () => {
137
123
  // SHOULD NOT BE EXECUTED, ONLY FOR STATIC TYPE TESTING
138
124
  // We use expect-error to statically test negative cases in typescript
139
125
  () => erp.item.create({
@@ -179,8 +165,8 @@ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", ()
179
165
  // @ts-expect-error should not be empty
180
166
  body: {},
181
167
  });
182
- }));
183
- test("Static Types with Input Optional", () => __awaiter(void 0, void 0, void 0, function* () {
168
+ });
169
+ test("Static Types with Input Optional", async () => {
184
170
  // DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
185
171
  // We use expect-error to statically test negative cases in typescript
186
172
  const testModel = zod_1.default.object({
@@ -200,8 +186,8 @@ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", ()
200
186
  const testOutput = {
201
187
  mandatory: "TEST",
202
188
  };
203
- }));
204
- test("Static Types with Nested Array Input Optional", () => __awaiter(void 0, void 0, void 0, function* () {
189
+ });
190
+ test("Static Types with Nested Array Input Optional", async () => {
205
191
  // DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
206
192
  // We use expect-error to statically test negative cases in typescript
207
193
  const testModel = zod_1.default.object({
@@ -239,9 +225,9 @@ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", ()
239
225
  },
240
226
  ],
241
227
  };
242
- }));
243
- test("Input for updateById function", () => __awaiter(void 0, void 0, void 0, function* () {
244
- () => __awaiter(void 0, void 0, void 0, function* () {
228
+ });
229
+ test("Input for updateById function", async () => {
230
+ async () => {
245
231
  // This static type test ensures, that Input as inferred here
246
232
  // conformes to the expected input type defined in doctypeResourceRequest -> updateById()
247
233
  const AddressInput = (0, zodContextOptionals_1.ResourceInput)(Address_1.Address);
@@ -252,10 +238,10 @@ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", ()
252
238
  country: "Country",
253
239
  pincode: "1234",
254
240
  };
255
- yield erp.address.updateById({
241
+ await erp.address.updateById({
256
242
  resourceId: "TEST",
257
243
  body: typedInputBody,
258
244
  });
259
- });
260
- }));
261
- }));
245
+ };
246
+ });
247
+ });