erpnext-queue-client 1.0.4 → 1.0.6
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.d.ts +6 -16
- package/dist/client.js +14 -39
- package/dist/erpnext/decryptFromErpNext.server.js +1 -1
- package/dist/erpnext/decryptFromErpNext.server.test.js +3 -3
- package/dist/erpnext/doctypes/country.d.ts +9 -0
- package/dist/erpnext/doctypes/country.js +28 -0
- package/dist/erpnext/erpnextRequests.d.ts +1 -1786
- package/dist/erpnext/erpnextRequests.js +13 -337
- package/dist/erpnext/model/Address.d.ts +48 -48
- package/dist/erpnext/model/Contact.d.ts +106 -106
- package/dist/erpnext/model/Country.d.ts +2 -2
- package/dist/erpnext/model/Customer.d.ts +4 -4
- package/dist/erpnext/model/DeliveryNote.d.ts +176 -176
- package/dist/erpnext/model/DispatchRun.d.ts +90 -90
- package/dist/erpnext/model/DispatcherPreset.d.ts +26 -26
- package/dist/erpnext/model/ERPNextQueue.d.ts +8 -7
- package/dist/erpnext/model/ERPNextRequest.d.ts +17 -0
- package/dist/erpnext/model/File.d.ts +4 -4
- package/dist/erpnext/model/Fulfiller.d.ts +11 -11
- package/dist/erpnext/model/FulfillerSettings.d.ts +6 -6
- package/dist/erpnext/model/Item.d.ts +204 -204
- package/dist/erpnext/model/ProjectedQuantityReport.d.ts +14 -14
- package/dist/erpnext/model/PurchaseOrder.d.ts +112 -112
- package/dist/erpnext/model/Receipt.d.ts +104 -104
- package/dist/erpnext/model/ReceiptDraft.d.ts +88 -88
- package/dist/erpnext/model/Shipment.d.ts +157 -157
- package/dist/erpnext/model/ShippingProvider.d.ts +23 -23
- package/dist/erpnext/resourceRequest.d.ts +16 -0
- package/dist/erpnext/resourceRequest.js +34 -0
- package/dist/erpnext.d.ts +20 -0
- package/dist/erpnext.js +45 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +21 -12
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
import { TypeOf, ZodTypeAny } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { ERPNextQueueType, TemporalClientContructorOptions } from "./erpnext/model/ERPNextQueue";
|
|
3
3
|
import { ERPNextRequestOptions } from "./erpnext/model/ERPNextRequest";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description Provide either a temporal client or connection details to create a new client
|
|
7
|
-
*/
|
|
8
|
-
export declare class ERPNextClient {
|
|
4
|
+
export declare class TemporalClient {
|
|
9
5
|
private client;
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
constructor(options: ERPNextQueueClientContructorOptions);
|
|
6
|
+
private options;
|
|
7
|
+
constructor(options: TemporalClientContructorOptions);
|
|
13
8
|
private tryConnect;
|
|
14
9
|
private createClient;
|
|
15
10
|
private getClient;
|
|
16
11
|
/**
|
|
17
|
-
* @description Execute
|
|
12
|
+
* @description Execute a ERPNext request workflow, 0 is the highest priority, 5 is default
|
|
18
13
|
*/
|
|
19
|
-
|
|
20
|
-
utils: {
|
|
21
|
-
decryptFromErpNext: (encryptedPassword: string) => string;
|
|
22
|
-
executeERPNextRequestWithoutTemporalQueue: <T extends ZodTypeAny, K extends ZodTypeAny>(options: ERPNextRequestOptions<T, K>) => Promise<TypeOf<T>>;
|
|
23
|
-
executeERPNextRequestDownloadFile: <T extends ZodTypeAny, K extends ZodTypeAny>(url: string) => Promise<Buffer<ArrayBufferLike>>;
|
|
24
|
-
};
|
|
14
|
+
executeERPNextRequestWorkflow<T extends ZodTypeAny, K extends ZodTypeAny>(requestName: string, options: ERPNextRequestOptions<T, K>, queue: ERPNextQueueType, priority?: number): Promise<TypeOf<T>>;
|
|
25
15
|
}
|
package/dist/client.js
CHANGED
|
@@ -20,47 +20,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.TemporalClient = void 0;
|
|
24
24
|
const client_1 = require("@temporalio/client");
|
|
25
25
|
const logger_1 = require("./utils/logger");
|
|
26
26
|
const zodUtils_1 = require("./utils/zodUtils");
|
|
27
27
|
const nanoid_1 = require("nanoid");
|
|
28
|
-
const erpnextRequestWrapper_1 = require("./erpnext/erpnextRequestWrapper");
|
|
29
|
-
const erpnextRequests_1 = require("./erpnext/erpnextRequests");
|
|
30
|
-
const decryptFromErpNext_server_1 = require("./erpnext/decryptFromErpNext.server");
|
|
31
28
|
const nanoid = (0, nanoid_1.customAlphabet)("1234567890", 4);
|
|
32
|
-
|
|
33
|
-
* @description Provide either a temporal client or connection details to create a new client
|
|
34
|
-
*/
|
|
35
|
-
class ERPNextClient {
|
|
29
|
+
class TemporalClient {
|
|
36
30
|
constructor(options) {
|
|
37
|
-
|
|
38
|
-
decryptFromErpNext: (encryptedPassword) => {
|
|
39
|
-
return (0, decryptFromErpNext_server_1.decryptFromErpNext)(this.credentials, encryptedPassword);
|
|
40
|
-
},
|
|
41
|
-
executeERPNextRequestWithoutTemporalQueue: (options) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
if (!this.credentials)
|
|
43
|
-
throw new Error("Direct API connection not possible. Please provide ERPNext API credentials.");
|
|
44
|
-
return yield (0, erpnextRequestWrapper_1.erpnextRequest)(this.credentials, options);
|
|
45
|
-
}),
|
|
46
|
-
executeERPNextRequestDownloadFile: (url) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
if (!this.credentials)
|
|
48
|
-
throw new Error("File download not possible. Please provide ERPNext API credentials.");
|
|
49
|
-
return yield (0, erpnextRequestWrapper_1.erpNextDownloadFile)(this.credentials, url);
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
const { client, erpnextCredentials, temporalCredentials } = options;
|
|
53
|
-
// Optional: initialize with ERPNext credentials for direct ERPNext connection
|
|
54
|
-
if (erpnextCredentials)
|
|
55
|
-
this.credentials = erpnextCredentials;
|
|
56
|
-
// Use existing client or create a new one
|
|
31
|
+
const { client } = options, clientOptions = __rest(options, ["client"]);
|
|
57
32
|
if (client)
|
|
58
33
|
this.client = client;
|
|
59
|
-
else if (
|
|
60
|
-
this.
|
|
34
|
+
else if (clientOptions.temporalHost)
|
|
35
|
+
this.options = clientOptions;
|
|
61
36
|
else
|
|
62
37
|
throw new Error("No client or connection details provided");
|
|
63
|
-
this.erpnext = (0, erpnextRequests_1.erpnextRequests)(this);
|
|
64
38
|
}
|
|
65
39
|
tryConnect(temporalHost, temporalCert, temporalKey) {
|
|
66
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -83,33 +57,34 @@ class ERPNextClient {
|
|
|
83
57
|
createClient(options) {
|
|
84
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
59
|
const connection = yield this.tryConnect(options.temporalHost, options.temporalCert, options.temporalKey);
|
|
60
|
+
console.log("Create new client", options.temporalHost);
|
|
86
61
|
this.client = new client_1.Client(Object.assign({ connection }, { namespace: options.temporalNamespace || "default" }));
|
|
87
62
|
return this.client;
|
|
88
63
|
});
|
|
89
64
|
}
|
|
90
|
-
getClient(
|
|
65
|
+
getClient() {
|
|
91
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
if (!this.client && !options)
|
|
67
|
+
if (!this.client && !this.options)
|
|
93
68
|
throw new Error("No client or connection details provided");
|
|
94
|
-
return this.client || (yield this.createClient(options));
|
|
69
|
+
return this.client || (yield this.createClient(this.options));
|
|
95
70
|
});
|
|
96
71
|
}
|
|
97
72
|
/**
|
|
98
|
-
* @description Execute
|
|
73
|
+
* @description Execute a ERPNext request workflow, 0 is the highest priority, 5 is default
|
|
99
74
|
*/
|
|
100
|
-
|
|
75
|
+
executeERPNextRequestWorkflow(requestName_1, options_1, queue_1) {
|
|
101
76
|
return __awaiter(this, arguments, void 0, function* (requestName, options, queue, priority = 5) {
|
|
102
77
|
if (process.env.NODE_ENV === "test")
|
|
103
78
|
return;
|
|
104
79
|
const runId = `${requestName}-${nanoid(4)}`;
|
|
105
80
|
const client = yield this.getClient();
|
|
106
|
-
|
|
81
|
+
logger_1.lg.info(`Enqueue to ERPNext Queue: ${options.url || options.uri || ""}${options.methodName || options.resourceName || ""}${options.resourceId || ""}${options.params || ""}`);
|
|
107
82
|
const { inputValidationModel, responseValidationModel } = options, optionsWithoutValidation = __rest(options, ["inputValidationModel", "responseValidationModel"]);
|
|
108
83
|
if (options.body && inputValidationModel)
|
|
109
84
|
(0, zodUtils_1.validateData)(options.body, inputValidationModel);
|
|
110
85
|
const data = yield client.workflow
|
|
111
86
|
.execute("erpnextRequestWorkflow", {
|
|
112
|
-
args: [optionsWithoutValidation
|
|
87
|
+
args: [optionsWithoutValidation],
|
|
113
88
|
taskQueue: priority < 5 ? `${queue}_priority` : queue, // add to priority queue if priority is 0-5
|
|
114
89
|
workflowId: runId,
|
|
115
90
|
})
|
|
@@ -138,4 +113,4 @@ class ERPNextClient {
|
|
|
138
113
|
});
|
|
139
114
|
}
|
|
140
115
|
}
|
|
141
|
-
exports.
|
|
116
|
+
exports.TemporalClient = TemporalClient;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.decryptFromErpNext = decryptFromErpNext;
|
|
4
4
|
const fernet_server_1 = require("../utils/fernet.server");
|
|
5
5
|
function decryptFromErpNext(credentials, encryptedPassword) {
|
|
6
|
-
if (!credentials.erpnextEncryptionKey)
|
|
6
|
+
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.erpnextEncryptionKey))
|
|
7
7
|
throw new Error("ERPNext encryption key is not defined. Please specify it to use the decryptFromErpNext() function.");
|
|
8
8
|
const encyptionKey = credentials.erpnextEncryptionKey;
|
|
9
9
|
const encodedEncyptionKey = new fernet_server_1.Secret(encyptionKey);
|
|
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const __1 = require("..");
|
|
13
13
|
describe("decryptFromErpNext", () => {
|
|
14
14
|
test("should decrypt password", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
const { utils
|
|
15
|
+
const { utils } = new __1.ERPNextQueueClient({
|
|
16
16
|
temporalCredentials: {
|
|
17
17
|
temporalHost: "temporalHost",
|
|
18
18
|
},
|
|
@@ -24,7 +24,7 @@ describe("decryptFromErpNext", () => {
|
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
const encryptedPassword = "gAAAAABjW77Rn3UP_3CZISSag2bsrq0huYiN5kavTd_2fUJUkcQd3tsrbsIbLk82TkqFKbwC1BnEP9iXKMQ-DrlIlLyIvZiwag==";
|
|
27
|
-
const decryptedPassword = decryptFromErpNext(encryptedPassword);
|
|
27
|
+
const decryptedPassword = utils.decryptFromErpNext(encryptedPassword);
|
|
28
28
|
expect(decryptedPassword).toBe("12345");
|
|
29
29
|
}));
|
|
30
30
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ERPNextCountry = void 0;
|
|
13
|
+
const Country_1 = require("../model/Country");
|
|
14
|
+
class ERPNextCountry {
|
|
15
|
+
constructor(client) {
|
|
16
|
+
this.getCountryList = () => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const result = yield this.client.executeERPNextRequestWorkflow("getCountryList", {
|
|
18
|
+
requestMethod: "GET",
|
|
19
|
+
responseValidationModel: (0, Country_1.CountryList)(["name", "code"]),
|
|
20
|
+
resourceName: "Country",
|
|
21
|
+
params: `?fields=["name", "code"]`,
|
|
22
|
+
}, "erpnext");
|
|
23
|
+
return result;
|
|
24
|
+
});
|
|
25
|
+
this.client = client;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ERPNextCountry = ERPNextCountry;
|