@hastehaul/common 3.4.0 → 3.6.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.
@@ -45,6 +45,7 @@ export declare enum AccountStatus {
45
45
  ResourceNotFoundError = 2306,// 2306 => Resource not found Error
46
46
  SystemError = 2307,// 2307 => System Error
47
47
  TooManyRequestError = 2308,// 2308 => Too Many request error
48
+ CustomerNotFound = 2309,// 2306 => Resource not found Error
48
49
  IncorrectOrNotFoundOTP = 2400,// 2400 => Incorrect/Not Found OTP
49
50
  OTPExpired = 2401
50
51
  }
@@ -57,6 +57,7 @@ var AccountStatus;
57
57
  AccountStatus[AccountStatus["ResourceNotFoundError"] = 2306] = "ResourceNotFoundError";
58
58
  AccountStatus[AccountStatus["SystemError"] = 2307] = "SystemError";
59
59
  AccountStatus[AccountStatus["TooManyRequestError"] = 2308] = "TooManyRequestError";
60
+ AccountStatus[AccountStatus["CustomerNotFound"] = 2309] = "CustomerNotFound";
60
61
  AccountStatus[AccountStatus["IncorrectOrNotFoundOTP"] = 2400] = "IncorrectOrNotFoundOTP";
61
62
  AccountStatus[AccountStatus["OTPExpired"] = 2401] = "OTPExpired";
62
63
  })(AccountStatus || (exports.AccountStatus = AccountStatus = {}));
@@ -9,6 +9,7 @@ export declare function formatDatetimeToHumanReadable(datetime: Date, format?: s
9
9
  export declare function generateIdentifier(messageContent: string): string;
10
10
  export declare function getValueFromSettings(settings: Setting[], key: string, envVar?: string, defaultValue?: any): any;
11
11
  export declare function loadAsset(relativePath: string): Promise<string | null>;
12
+ export declare function loadAssetStream(relativePath: string): Promise<any>;
12
13
  export declare function isPointInGeoJSON(latLng: number[], fileName: string): Promise<{
13
14
  isInside: boolean;
14
15
  properties: any;
@@ -18,13 +18,15 @@ exports.formatDatetimeToHumanReadable = formatDatetimeToHumanReadable;
18
18
  exports.generateIdentifier = generateIdentifier;
19
19
  exports.getValueFromSettings = getValueFromSettings;
20
20
  exports.loadAsset = loadAsset;
21
+ exports.loadAssetStream = loadAssetStream;
21
22
  exports.isPointInGeoJSON = isPointInGeoJSON;
22
23
  exports.clearGeoJsonCache = clearGeoJsonCache;
23
24
  exports.generateCode = generateCode;
25
+ const fs_1 = __importDefault(require("fs"));
24
26
  const boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon"));
25
27
  const helpers_1 = require("@turf/helpers");
26
28
  const moment_1 = __importDefault(require("moment"));
27
- const fs_1 = require("fs");
29
+ const fs_2 = require("fs");
28
30
  const boolean_point_on_line_1 = __importDefault(require("@turf/boolean-point-on-line"));
29
31
  function hasElapsed(expirationDate) {
30
32
  const currentDate = (0, moment_1.default)();
@@ -53,7 +55,7 @@ function getValueFromSettings(settings, key, envVar, defaultValue) {
53
55
  function loadAsset(relativePath) {
54
56
  return __awaiter(this, void 0, void 0, function* () {
55
57
  try {
56
- const fileContent = yield fs_1.promises.readFile(relativePath, 'utf-8');
58
+ const fileContent = yield fs_2.promises.readFile(relativePath, 'utf-8');
57
59
  return fileContent;
58
60
  }
59
61
  catch (error) {
@@ -62,6 +64,31 @@ function loadAsset(relativePath) {
62
64
  }
63
65
  });
64
66
  }
67
+ function loadAssetStream(relativePath) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return new Promise((resolve, reject) => {
70
+ let fileContent = '';
71
+ const stream = fs_1.default.createReadStream(relativePath, 'utf-8');
72
+ stream.on('data', (chunk) => {
73
+ fileContent += chunk;
74
+ });
75
+ stream.on('end', () => {
76
+ try {
77
+ const geoJsonData = JSON.parse(fileContent);
78
+ resolve(geoJsonData);
79
+ }
80
+ catch (error) {
81
+ console.error(`Error parsing JSON: ${error.message}`);
82
+ reject(error);
83
+ }
84
+ });
85
+ stream.on('error', (error) => {
86
+ console.error(`Error loading asset: ${error.message}`);
87
+ reject(error);
88
+ });
89
+ });
90
+ });
91
+ }
65
92
  let cachedGeoJsonData = null;
66
93
  function isPointInGeoJSON(latLng, fileName) {
67
94
  return __awaiter(this, void 0, void 0, function* () {
@@ -70,7 +97,7 @@ function isPointInGeoJSON(latLng, fileName) {
70
97
  return { isInside: false, properties: null };
71
98
  // Load and parse GeoJSON data only if not already cached
72
99
  if (!cachedGeoJsonData) {
73
- const geoJsonData = yield loadAsset(fileName);
100
+ const geoJsonData = yield loadAssetStream(fileName);
74
101
  cachedGeoJsonData = JSON.parse(geoJsonData);
75
102
  }
76
103
  // !NB points take the form longitude, latitude
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "bullmq": "^5.8.3",
35
35
  "express": "^4.18.2",
36
36
  "ioredis": "^5.3.2",
37
+ "JSONStream": "^1.3.5",
37
38
  "jsonwebtoken": "^9.0.1",
38
39
  "moment": "^2.29.4",
39
40
  "mongoose": "^8.5.2",