@machinemetrics/mm-erp-sdk 0.1.8-beta.0 → 0.1.8-beta.2

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.
@@ -1,14 +1,14 @@
1
- import { C as CoreConfiguration, H as HashedCacheManager } from "./hashed-cache-manager-B6hTDLxU.js";
2
- import { E, g, a } from "./hashed-cache-manager-B6hTDLxU.js";
3
- import { l as logger } from "./logger-SqdNut1H.js";
4
- import { g as getCachedMMToken, s as setCachedMMToken, a as setTimezoneOffsetInCache, b as getCachedTimezoneOffset, S as SQLiteCoordinator } from "./index-Bg76oouR.js";
5
- import { c, d } from "./index-Bg76oouR.js";
1
+ import { C as CoreConfiguration, H as HashedCacheManager } from "./hashed-cache-manager-BnviJzB7.js";
2
+ import { E, g, a } from "./hashed-cache-manager-BnviJzB7.js";
3
+ import { l as logger } from "./logger-HAWySEbs.js";
4
+ import { g as getCachedMMToken, s as setCachedMMToken, a as setTimezoneOffsetInCache, b as getCachedTimezoneOffset, S as SQLiteCoordinator } from "./index-DNqHWa8F.js";
5
+ import { c, d } from "./index-DNqHWa8F.js";
6
6
  import axios, { AxiosError } from "axios";
7
7
  import knex from "knex";
8
8
  import { c as config } from "./knexfile-1qKKIORB.js";
9
9
  import fs from "fs";
10
10
  import path from "path";
11
- import "./connector-factory-D8v6aQIt.js";
11
+ import "./connector-factory-wivcyMhC.js";
12
12
  import Bree from "bree";
13
13
  import Graceful from "@ladjs/graceful";
14
14
  import { fileURLToPath } from "url";
@@ -1,7 +1,7 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { H as HashedCacheManager } from "../../../hashed-cache-manager-B6hTDLxU.js";
3
- import { S as SQLiteCoordinator } from "../../../index-Bg76oouR.js";
4
- import { l as logger } from "../../../logger-SqdNut1H.js";
1
+ import "../../../config-152LkbTv.js";
2
+ import { H as HashedCacheManager } from "../../../hashed-cache-manager-BnviJzB7.js";
3
+ import { S as SQLiteCoordinator } from "../../../index-DNqHWa8F.js";
4
+ import { l as logger } from "../../../logger-HAWySEbs.js";
5
5
  logger.level = process.env.LOG_LEVEL || "info";
6
6
  const main = async () => {
7
7
  const cacheManager = new HashedCacheManager();
@@ -1,7 +1,7 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
3
- import { S as SQLiteCoordinator } from "../../../index-Bg76oouR.js";
4
- import { c as createConnectorFromPath } from "../../../connector-factory-D8v6aQIt.js";
1
+ import "../../../config-152LkbTv.js";
2
+ import { l as logger } from "../../../logger-HAWySEbs.js";
3
+ import { S as SQLiteCoordinator } from "../../../index-DNqHWa8F.js";
4
+ import { c as createConnectorFromPath } from "../../../connector-factory-wivcyMhC.js";
5
5
  logger.level = process.env.LOG_LEVEL || "info";
6
6
  const main = async () => {
7
7
  try {
@@ -1,6 +1,6 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
3
- import { c as createConnectorFromPath } from "../../../connector-factory-D8v6aQIt.js";
1
+ import "../../../config-152LkbTv.js";
2
+ import { l as logger } from "../../../logger-HAWySEbs.js";
3
+ import { c as createConnectorFromPath } from "../../../connector-factory-wivcyMhC.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
5
  const main = async () => {
6
6
  try {
@@ -1,5 +1,5 @@
1
1
  import knex from "knex";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
2
+ import { l as logger } from "../../../logger-HAWySEbs.js";
3
3
  import { c as config } from "../../../knexfile-1qKKIORB.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
5
  const db = knex(config.local);
@@ -1,6 +1,6 @@
1
- import "../../../config-CV-KosWV.js";
2
- import { l as logger } from "../../../logger-SqdNut1H.js";
3
- import { c as createConnectorFromPath } from "../../../connector-factory-D8v6aQIt.js";
1
+ import "../../../config-152LkbTv.js";
2
+ import { l as logger } from "../../../logger-HAWySEbs.js";
3
+ import { c as createConnectorFromPath } from "../../../connector-factory-wivcyMhC.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
5
  const main = async () => {
6
6
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/services/reporting-service/logger.ts"],"names":[],"mappings":"AA+DA,QAAA,MAAM,MAAM,0BAaV,CAAC;AAGH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,SA2GhE,CAAC;AAKF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/services/reporting-service/logger.ts"],"names":[],"mappings":"AA+DA,QAAA,MAAM,MAAM,0BAaV,CAAC;AA+EH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,SAuChE,CAAC;AAKF,eAAe,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-erp-sdk",
3
3
  "description": "A library for syncing data between MachineMetrics and ERP systems",
4
- "version": "0.1.8-beta.0",
4
+ "version": "0.1.8-beta.2",
5
5
  "license": "MIT",
6
6
  "author": "machinemetrics",
7
7
  "main": "dist/mm-erp-sdk.js",
@@ -76,6 +76,82 @@ const logger = createLogger({
76
76
  ],
77
77
  });
78
78
 
79
+ // Helper function to create a file transport with shared configuration
80
+ const createFileTransport = (): DailyRotateFile => {
81
+ return new DailyRotateFile({
82
+ filename: path.join(logDirectory, "%DATE%.log"),
83
+ datePattern: "YYYY-MM-DD",
84
+ zippedArchive: true,
85
+ maxSize: "20m",
86
+ maxFiles: "14d",
87
+ format: logFormat,
88
+ });
89
+ };
90
+
91
+ // Rotate mitigation helper: attaches rotate handler to transport and recursively attaches to replacements
92
+ function attachRotateMitigation(
93
+ transport: DailyRotateFile,
94
+ opts: { logLevel: string; nodeEnv: string }
95
+ ) {
96
+ const { logLevel, nodeEnv } = opts;
97
+ let isRefreshing = false;
98
+ transport.on("rotate", (_old: string, _new: string) => {
99
+ if (isRefreshing) return;
100
+ isRefreshing = true;
101
+ (logger as any).silent = true;
102
+
103
+ const REFRESH_TIMEOUT_MS = 10000;
104
+ let timeout: NodeJS.Timeout | null = setTimeout(() => {
105
+ (logger as any).silent = false;
106
+ isRefreshing = false;
107
+ console.warn(
108
+ '[logger] Refresh timeout: resuming logging after 10s without "new" event.'
109
+ );
110
+ }, REFRESH_TIMEOUT_MS);
111
+
112
+ // Close and clear existing file transports
113
+ const existing = (logger.transports || []).filter(
114
+ (t: any) => t instanceof DailyRotateFile
115
+ );
116
+ for (const t of existing) {
117
+ const s = (t as any).logStream;
118
+ if (s && typeof s.end === "function") {
119
+ try {
120
+ s.end();
121
+ } catch {}
122
+ }
123
+ }
124
+ logger.clear();
125
+
126
+ // Create replacement, attach mitigation for future rotations
127
+ const next = createFileTransport();
128
+ next.on("new", () => {
129
+ if (timeout) {
130
+ clearTimeout(timeout);
131
+ timeout = null;
132
+ }
133
+ (logger as any).silent = false;
134
+ isRefreshing = false;
135
+ });
136
+ attachRotateMitigation(next, opts);
137
+
138
+ logger.add(next);
139
+ if (nodeEnv !== "production") {
140
+ logger.add(
141
+ new transports.Console({
142
+ format: format.combine(
143
+ format.timestamp(),
144
+ format.splat(),
145
+ baseFormat,
146
+ format.colorize({ all: true })
147
+ ),
148
+ })
149
+ );
150
+ }
151
+ logger.level = logLevel;
152
+ });
153
+ }
154
+
79
155
  // Function to reconfigure the logger once CoreConfiguration is available
80
156
  export const configureLogger = (logLevel: string, nodeEnv: string) => {
81
157
  // Remove existing transports (safely): close any DailyRotateFile streams first
@@ -96,78 +172,10 @@ export const configureLogger = (logLevel: string, nodeEnv: string) => {
96
172
  logger.clear();
97
173
 
98
174
  // Add file transport
99
- const fileTransport = new DailyRotateFile({
100
- filename: path.join(logDirectory, "%DATE%.log"),
101
- datePattern: "YYYY-MM-DD",
102
- zippedArchive: true,
103
- maxSize: "20m",
104
- maxFiles: "14d",
105
- format: logFormat,
106
- });
175
+ const fileTransport = createFileTransport();
176
+ attachRotateMitigation(fileTransport, { logLevel, nodeEnv });
107
177
  logger.add(fileTransport);
108
178
 
109
- // Rotate-time mitigation for long-running single-process apps
110
- let isRefreshing = false;
111
- fileTransport.on("rotate", (_oldFilename: string, _newFilename: string) => {
112
- if (isRefreshing) return;
113
- isRefreshing = true;
114
- (logger as any).silent = true; // gate writes during refresh to avoid write-after-end
115
-
116
- try {
117
- // Close all existing DailyRotateFile streams
118
- const existing = (logger.transports || []).filter(
119
- (t: any) => t instanceof DailyRotateFile
120
- );
121
- for (const t of existing) {
122
- const s = (t as any).logStream;
123
- if (s && typeof s.end === "function") {
124
- try {
125
- s.end();
126
- } catch {}
127
- }
128
- }
129
-
130
- // Refresh the file transport cleanly
131
- logger.clear();
132
- const refreshed = new DailyRotateFile({
133
- filename: path.join(logDirectory, "%DATE%.log"),
134
- datePattern: "YYYY-MM-DD",
135
- zippedArchive: true,
136
- maxSize: "20m",
137
- maxFiles: "14d",
138
- format: logFormat,
139
- });
140
-
141
- // Once new file stream is ready, resume writes
142
- refreshed.on("new", () => {
143
- (logger as any).silent = false;
144
- isRefreshing = false;
145
- });
146
-
147
- logger.add(refreshed);
148
-
149
- // Preserve console transport behavior in non-production
150
- if (nodeEnv !== "production") {
151
- logger.add(
152
- new transports.Console({
153
- format: format.combine(
154
- format.timestamp(),
155
- format.splat(),
156
- baseFormat,
157
- format.colorize({ all: true })
158
- ),
159
- })
160
- );
161
- }
162
-
163
- logger.level = logLevel;
164
- } catch {
165
- // If anything goes wrong, resume writes to avoid permanent silence
166
- (logger as any).silent = false;
167
- isRefreshing = false;
168
- }
169
- });
170
-
171
179
  // Add console transport in non-production environments
172
180
  if (nodeEnv !== "production") {
173
181
  logger.add(