@dracoonghost/trndup-sdk 1.3.25 → 1.3.26
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/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +56 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1819,6 +1819,10 @@ declare class TrndUpClient {
|
|
|
1819
1819
|
patch<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
1820
1820
|
delete<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
|
|
1821
1821
|
private request;
|
|
1822
|
+
private logRequest;
|
|
1823
|
+
private logResponse;
|
|
1824
|
+
private logError;
|
|
1825
|
+
private truncateObject;
|
|
1822
1826
|
private buildUrl;
|
|
1823
1827
|
private buildHeaders;
|
|
1824
1828
|
private handleResponse;
|
package/dist/index.d.ts
CHANGED
|
@@ -1819,6 +1819,10 @@ declare class TrndUpClient {
|
|
|
1819
1819
|
patch<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
1820
1820
|
delete<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
|
|
1821
1821
|
private request;
|
|
1822
|
+
private logRequest;
|
|
1823
|
+
private logResponse;
|
|
1824
|
+
private logError;
|
|
1825
|
+
private truncateObject;
|
|
1822
1826
|
private buildUrl;
|
|
1823
1827
|
private buildHeaders;
|
|
1824
1828
|
private handleResponse;
|
package/dist/index.js
CHANGED
|
@@ -83,19 +83,27 @@ var TrndUpClient = class {
|
|
|
83
83
|
() => controller.abort(),
|
|
84
84
|
timeout ?? this.config.timeout
|
|
85
85
|
);
|
|
86
|
+
const startTime = Date.now();
|
|
86
87
|
try {
|
|
87
88
|
if (this.config.debug) {
|
|
88
|
-
|
|
89
|
+
this.logRequest(method, url, body);
|
|
89
90
|
}
|
|
90
91
|
const response = await fetch(url, {
|
|
91
92
|
...init,
|
|
92
93
|
signal: signal ?? controller.signal
|
|
93
94
|
});
|
|
94
95
|
clearTimeout(timeoutId);
|
|
95
|
-
|
|
96
|
+
const result = await this.handleResponse(response, path);
|
|
97
|
+
if (this.config.debug) {
|
|
98
|
+
this.logResponse(method, path, response.status, result, startTime);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
96
101
|
} catch (error) {
|
|
97
102
|
clearTimeout(timeoutId);
|
|
98
103
|
if (error instanceof TrndUpApiError) {
|
|
104
|
+
if (this.config.debug) {
|
|
105
|
+
this.logError(method, path, error, startTime);
|
|
106
|
+
}
|
|
99
107
|
throw error;
|
|
100
108
|
}
|
|
101
109
|
const networkError = new TrndUpNetworkError(
|
|
@@ -103,11 +111,56 @@ var TrndUpClient = class {
|
|
|
103
111
|
path
|
|
104
112
|
);
|
|
105
113
|
if (this.config.debug) {
|
|
106
|
-
|
|
114
|
+
this.logError(method, path, networkError, startTime);
|
|
107
115
|
}
|
|
108
116
|
throw networkError;
|
|
109
117
|
}
|
|
110
118
|
}
|
|
119
|
+
// =============================================================================
|
|
120
|
+
// LOGGING HELPERS
|
|
121
|
+
// =============================================================================
|
|
122
|
+
logRequest(method, url, body) {
|
|
123
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1].slice(0, 12);
|
|
124
|
+
const bodyPreview = body ? this.truncateObject(body, 200) : void 0;
|
|
125
|
+
console.log(
|
|
126
|
+
`\x1B[36m[${timestamp}]\x1B[0m \x1B[33m\u2192 ${method}\x1B[0m ${url}` + (bodyPreview ? `
|
|
127
|
+
\x1B[90mbody:\x1B[0m ${bodyPreview}` : "")
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
logResponse(method, path, status, data, startTime) {
|
|
131
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1].slice(0, 12);
|
|
132
|
+
const duration = Date.now() - startTime;
|
|
133
|
+
const statusColor = status >= 200 && status < 300 ? "\x1B[32m" : "\x1B[31m";
|
|
134
|
+
const dataPreview = this.truncateObject(data, 300);
|
|
135
|
+
console.log(
|
|
136
|
+
`\x1B[36m[${timestamp}]\x1B[0m ${statusColor}\u2190 ${status}\x1B[0m ${method} ${path} \x1B[90m(${duration}ms)\x1B[0m
|
|
137
|
+
\x1B[90mdata:\x1B[0m ${dataPreview}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
logError(method, path, error, startTime) {
|
|
141
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1].slice(0, 12);
|
|
142
|
+
const duration = Date.now() - startTime;
|
|
143
|
+
if (error instanceof TrndUpApiError) {
|
|
144
|
+
console.log(
|
|
145
|
+
`\x1B[36m[${timestamp}]\x1B[0m \x1B[31m\u2715 ${error.status}\x1B[0m ${method} ${path} \x1B[90m(${duration}ms)\x1B[0m
|
|
146
|
+
\x1B[31merror:\x1B[0m ${error.code || "UNKNOWN"} - ${error.message}`
|
|
147
|
+
);
|
|
148
|
+
} else {
|
|
149
|
+
console.log(
|
|
150
|
+
`\x1B[36m[${timestamp}]\x1B[0m \x1B[31m\u2715 NETWORK\x1B[0m ${method} ${path} \x1B[90m(${duration}ms)\x1B[0m
|
|
151
|
+
\x1B[31merror:\x1B[0m ${error.message}`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
truncateObject(obj, maxLength) {
|
|
156
|
+
try {
|
|
157
|
+
const str = JSON.stringify(obj);
|
|
158
|
+
if (str.length <= maxLength) return str;
|
|
159
|
+
return str.slice(0, maxLength) + "...";
|
|
160
|
+
} catch {
|
|
161
|
+
return "[Unable to serialize]";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
111
164
|
buildUrl(path, params) {
|
|
112
165
|
const url = new URL(`${this.config.baseUrl}${path}`);
|
|
113
166
|
if (params) {
|
|
@@ -164,9 +217,6 @@ var TrndUpClient = class {
|
|
|
164
217
|
if (apiError.isAuthError() && this.config.onAuthFailure) {
|
|
165
218
|
await this.config.onAuthFailure();
|
|
166
219
|
}
|
|
167
|
-
if (this.config.debug) {
|
|
168
|
-
console.error("[TrndUp SDK] API error:", apiError);
|
|
169
|
-
}
|
|
170
220
|
throw apiError;
|
|
171
221
|
}
|
|
172
222
|
if (isJson) {
|