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.
Files changed (34) hide show
  1. package/dist/client.d.ts +6 -16
  2. package/dist/client.js +14 -39
  3. package/dist/erpnext/decryptFromErpNext.server.js +1 -1
  4. package/dist/erpnext/decryptFromErpNext.server.test.js +3 -3
  5. package/dist/erpnext/doctypes/country.d.ts +9 -0
  6. package/dist/erpnext/doctypes/country.js +28 -0
  7. package/dist/erpnext/erpnextRequests.d.ts +1 -1786
  8. package/dist/erpnext/erpnextRequests.js +13 -337
  9. package/dist/erpnext/model/Address.d.ts +48 -48
  10. package/dist/erpnext/model/Contact.d.ts +106 -106
  11. package/dist/erpnext/model/Country.d.ts +2 -2
  12. package/dist/erpnext/model/Customer.d.ts +4 -4
  13. package/dist/erpnext/model/DeliveryNote.d.ts +176 -176
  14. package/dist/erpnext/model/DispatchRun.d.ts +90 -90
  15. package/dist/erpnext/model/DispatcherPreset.d.ts +26 -26
  16. package/dist/erpnext/model/ERPNextQueue.d.ts +8 -7
  17. package/dist/erpnext/model/ERPNextRequest.d.ts +17 -0
  18. package/dist/erpnext/model/File.d.ts +4 -4
  19. package/dist/erpnext/model/Fulfiller.d.ts +11 -11
  20. package/dist/erpnext/model/FulfillerSettings.d.ts +6 -6
  21. package/dist/erpnext/model/Item.d.ts +204 -204
  22. package/dist/erpnext/model/ProjectedQuantityReport.d.ts +14 -14
  23. package/dist/erpnext/model/PurchaseOrder.d.ts +112 -112
  24. package/dist/erpnext/model/Receipt.d.ts +104 -104
  25. package/dist/erpnext/model/ReceiptDraft.d.ts +88 -88
  26. package/dist/erpnext/model/Shipment.d.ts +157 -157
  27. package/dist/erpnext/model/ShippingProvider.d.ts +23 -23
  28. package/dist/erpnext/resourceRequest.d.ts +16 -0
  29. package/dist/erpnext/resourceRequest.js +34 -0
  30. package/dist/erpnext.d.ts +20 -0
  31. package/dist/erpnext.js +45 -0
  32. package/dist/index.d.ts +17 -1
  33. package/dist/index.js +21 -12
  34. package/package.json +1 -1
package/dist/client.d.ts CHANGED
@@ -1,25 +1,15 @@
1
1
  import { TypeOf, ZodTypeAny } from "zod";
2
- import { ERPNextQueueClientContructorOptions, ERPNextQueueType } from "./erpnext/model/ERPNextQueue";
2
+ import { ERPNextQueueType, TemporalClientContructorOptions } from "./erpnext/model/ERPNextQueue";
3
3
  import { ERPNextRequestOptions } from "./erpnext/model/ERPNextRequest";
4
- import { erpnextRequests } from "./erpnext/erpnextRequests";
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 credentials;
11
- erpnext: ReturnType<typeof erpnextRequests>;
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 an ERPNext request workflow, 0 is the highest priority, 5 is default
12
+ * @description Execute a ERPNext request workflow, 0 is the highest priority, 5 is default
18
13
  */
19
- executeERPNextRequest<T extends ZodTypeAny, K extends ZodTypeAny>(requestName: string, options: ERPNextRequestOptions<T, K>, queue: ERPNextQueueType, priority?: number): Promise<TypeOf<T>>;
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.ERPNextClient = void 0;
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
- this.utils = {
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 (temporalCredentials.temporalHost)
60
- this.createClient(temporalCredentials);
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(options) {
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 an ERPNext request workflow, 0 is the highest priority, 5 is default
73
+ * @description Execute a ERPNext request workflow, 0 is the highest priority, 5 is default
99
74
  */
100
- executeERPNextRequest(requestName_1, options_1, queue_1) {
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
- console.log(`Enqueue to ERPNext Queue: ${options.uri || options.url}`);
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, priority],
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.ERPNextClient = ERPNextClient;
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 client_1 = require("../client");
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: { decryptFromErpNext }, } = new client_1.ERPNextClient({
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,9 @@
1
+ import { TemporalClient } from "../../client";
2
+ export declare class ERPNextCountry {
3
+ private client;
4
+ constructor(client: TemporalClient);
5
+ getCountryList: () => Promise<{
6
+ code?: string;
7
+ name?: string;
8
+ }[]>;
9
+ }
@@ -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;