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