@topolo/sdk 0.11.3 → 0.11.5
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.cjs +30 -9
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -9
- package/dist/node/credential-store.cjs +1 -0
- package/dist/node/credential-store.js +1 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -153,6 +153,7 @@ var PUBLIC_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
153
153
|
"permission_denied",
|
|
154
154
|
"rate_limited",
|
|
155
155
|
"request_failed",
|
|
156
|
+
"request_timeout",
|
|
156
157
|
"service_catalog_unavailable",
|
|
157
158
|
"service_path_origin_mismatch",
|
|
158
159
|
"service_required",
|
|
@@ -1138,7 +1139,7 @@ var TopoloClient = class _TopoloClient {
|
|
|
1138
1139
|
this.serviceUrls = options.environment ? topoloServiceOrigins(options.serviceUrls, options.environment) : options.serviceUrls;
|
|
1139
1140
|
this.appIds = options.appIds;
|
|
1140
1141
|
this.requireConfirmForWrites = options.requireConfirmForWrites !== false;
|
|
1141
|
-
this.timeoutMs = options.timeoutMs ??
|
|
1142
|
+
this.timeoutMs = options.timeoutMs ?? 12e4;
|
|
1142
1143
|
this.fetchImpl = options.fetch ?? fetch;
|
|
1143
1144
|
this.credentialProvider = options.credentialProvider;
|
|
1144
1145
|
this.refreshCredential = options.refreshCredential;
|
|
@@ -1209,7 +1210,11 @@ var TopoloClient = class _TopoloClient {
|
|
|
1209
1210
|
this.emit({ phase: "request", method, service: resolvedService.serviceKey, path: opts.path, url: urlStr, requestId });
|
|
1210
1211
|
const fetchOnce = async () => {
|
|
1211
1212
|
const controller = new AbortController();
|
|
1212
|
-
|
|
1213
|
+
let timedOut = false;
|
|
1214
|
+
const timeoutId = setTimeout(() => {
|
|
1215
|
+
timedOut = true;
|
|
1216
|
+
controller.abort();
|
|
1217
|
+
}, this.timeoutMs);
|
|
1213
1218
|
const signal = opts.signal ? mergeSignals(opts.signal, controller.signal) : controller.signal;
|
|
1214
1219
|
try {
|
|
1215
1220
|
return await this.fetchImpl(urlStr, {
|
|
@@ -1218,6 +1223,14 @@ var TopoloClient = class _TopoloClient {
|
|
|
1218
1223
|
body: opts.rawBody ?? (opts.body !== void 0 ? JSON.stringify(opts.body) : null),
|
|
1219
1224
|
signal
|
|
1220
1225
|
});
|
|
1226
|
+
} catch (error) {
|
|
1227
|
+
if (timedOut) {
|
|
1228
|
+
throw new TopoloSdkError(
|
|
1229
|
+
"request_timeout",
|
|
1230
|
+
`Topolo request timed out after ${this.timeoutMs}ms. Verify current state before retrying a mutation.`
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
throw error;
|
|
1221
1234
|
} finally {
|
|
1222
1235
|
clearTimeout(timeoutId);
|
|
1223
1236
|
}
|
|
@@ -1243,7 +1256,7 @@ var TopoloClient = class _TopoloClient {
|
|
|
1243
1256
|
url: urlStr,
|
|
1244
1257
|
requestId,
|
|
1245
1258
|
durationMs: Date.now() - startedAt,
|
|
1246
|
-
error: "network_error"
|
|
1259
|
+
error: err instanceof TopoloSdkError ? err.code : "network_error"
|
|
1247
1260
|
});
|
|
1248
1261
|
throw err;
|
|
1249
1262
|
}
|
|
@@ -2230,11 +2243,12 @@ function compactExample(input) {
|
|
|
2230
2243
|
function compactActionValidation(actionId, validation) {
|
|
2231
2244
|
return { actionId, valid: validation.valid, errors: validation.errors };
|
|
2232
2245
|
}
|
|
2233
|
-
var ACTION_RESULT_MAX_DEPTH =
|
|
2234
|
-
var ACTION_RESULT_MAX_KEYS =
|
|
2235
|
-
var
|
|
2236
|
-
var
|
|
2237
|
-
var
|
|
2246
|
+
var ACTION_RESULT_MAX_DEPTH = 3;
|
|
2247
|
+
var ACTION_RESULT_MAX_KEYS = 12;
|
|
2248
|
+
var ACTION_RESULT_MAX_ORDINARY_KEYS = 5;
|
|
2249
|
+
var ACTION_RESULT_MAX_ITEMS = 3;
|
|
2250
|
+
var ACTION_RESULT_MAX_SCALARS = 60;
|
|
2251
|
+
var ACTION_RESULT_MAX_STRING = 256;
|
|
2238
2252
|
function resultKeyPriority(key) {
|
|
2239
2253
|
if (/^(id|requestId|status|state|url|slug|name|title|version)$/i.test(key)) return 0;
|
|
2240
2254
|
if (/(Id|Ids|Url|Uri|Status|State|Count|Total|Version|CreatedAt|UpdatedAt)$/i.test(key)) return 1;
|
|
@@ -2260,7 +2274,14 @@ function compactResultValue(value, depth, budget) {
|
|
|
2260
2274
|
if (typeof value === "object") {
|
|
2261
2275
|
const record = value;
|
|
2262
2276
|
const allKeys = Object.keys(record);
|
|
2263
|
-
const
|
|
2277
|
+
const ranked = allKeys.sort((left, right) => resultKeyPriority(left) - resultKeyPriority(right));
|
|
2278
|
+
const prioritized = ranked.filter((key) => resultKeyPriority(key) < 2);
|
|
2279
|
+
const ordinary = ranked.filter((key) => resultKeyPriority(key) === 2);
|
|
2280
|
+
const ordinaryLimit = depth === 0 ? ACTION_RESULT_MAX_ORDINARY_KEYS : prioritized.length ? 1 : ACTION_RESULT_MAX_ORDINARY_KEYS;
|
|
2281
|
+
const keys = [
|
|
2282
|
+
...prioritized,
|
|
2283
|
+
...ordinary.slice(0, ordinaryLimit)
|
|
2284
|
+
].slice(0, ACTION_RESULT_MAX_KEYS);
|
|
2264
2285
|
const compact = Object.fromEntries(keys.map((key) => [key, compactResultValue(record[key], depth + 1, budget)]));
|
|
2265
2286
|
if (allKeys.length > keys.length) compact["_omittedKeys"] = allKeys.length - keys.length;
|
|
2266
2287
|
return compact;
|
package/dist/index.d.cts
CHANGED
|
@@ -95,7 +95,7 @@ interface TopoloClientOptions {
|
|
|
95
95
|
* `{ confirm: true }`. Defaults to true. Set false only for trusted surfaces.
|
|
96
96
|
*/
|
|
97
97
|
requireConfirmForWrites?: boolean;
|
|
98
|
-
/** HTTP request timeout (ms). Default
|
|
98
|
+
/** HTTP request timeout (ms). Default 120s. */
|
|
99
99
|
timeoutMs?: number;
|
|
100
100
|
/** Injected fetch, for testing. Defaults to global fetch. */
|
|
101
101
|
fetch?: typeof fetch;
|
package/dist/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ interface TopoloClientOptions {
|
|
|
95
95
|
* `{ confirm: true }`. Defaults to true. Set false only for trusted surfaces.
|
|
96
96
|
*/
|
|
97
97
|
requireConfirmForWrites?: boolean;
|
|
98
|
-
/** HTTP request timeout (ms). Default
|
|
98
|
+
/** HTTP request timeout (ms). Default 120s. */
|
|
99
99
|
timeoutMs?: number;
|
|
100
100
|
/** Injected fetch, for testing. Defaults to global fetch. */
|
|
101
101
|
fetch?: typeof fetch;
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ var PUBLIC_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
63
63
|
"permission_denied",
|
|
64
64
|
"rate_limited",
|
|
65
65
|
"request_failed",
|
|
66
|
+
"request_timeout",
|
|
66
67
|
"service_catalog_unavailable",
|
|
67
68
|
"service_path_origin_mismatch",
|
|
68
69
|
"service_required",
|
|
@@ -1048,7 +1049,7 @@ var TopoloClient = class _TopoloClient {
|
|
|
1048
1049
|
this.serviceUrls = options.environment ? topoloServiceOrigins(options.serviceUrls, options.environment) : options.serviceUrls;
|
|
1049
1050
|
this.appIds = options.appIds;
|
|
1050
1051
|
this.requireConfirmForWrites = options.requireConfirmForWrites !== false;
|
|
1051
|
-
this.timeoutMs = options.timeoutMs ??
|
|
1052
|
+
this.timeoutMs = options.timeoutMs ?? 12e4;
|
|
1052
1053
|
this.fetchImpl = options.fetch ?? fetch;
|
|
1053
1054
|
this.credentialProvider = options.credentialProvider;
|
|
1054
1055
|
this.refreshCredential = options.refreshCredential;
|
|
@@ -1119,7 +1120,11 @@ var TopoloClient = class _TopoloClient {
|
|
|
1119
1120
|
this.emit({ phase: "request", method, service: resolvedService.serviceKey, path: opts.path, url: urlStr, requestId });
|
|
1120
1121
|
const fetchOnce = async () => {
|
|
1121
1122
|
const controller = new AbortController();
|
|
1122
|
-
|
|
1123
|
+
let timedOut = false;
|
|
1124
|
+
const timeoutId = setTimeout(() => {
|
|
1125
|
+
timedOut = true;
|
|
1126
|
+
controller.abort();
|
|
1127
|
+
}, this.timeoutMs);
|
|
1123
1128
|
const signal = opts.signal ? mergeSignals(opts.signal, controller.signal) : controller.signal;
|
|
1124
1129
|
try {
|
|
1125
1130
|
return await this.fetchImpl(urlStr, {
|
|
@@ -1128,6 +1133,14 @@ var TopoloClient = class _TopoloClient {
|
|
|
1128
1133
|
body: opts.rawBody ?? (opts.body !== void 0 ? JSON.stringify(opts.body) : null),
|
|
1129
1134
|
signal
|
|
1130
1135
|
});
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
if (timedOut) {
|
|
1138
|
+
throw new TopoloSdkError(
|
|
1139
|
+
"request_timeout",
|
|
1140
|
+
`Topolo request timed out after ${this.timeoutMs}ms. Verify current state before retrying a mutation.`
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
throw error;
|
|
1131
1144
|
} finally {
|
|
1132
1145
|
clearTimeout(timeoutId);
|
|
1133
1146
|
}
|
|
@@ -1153,7 +1166,7 @@ var TopoloClient = class _TopoloClient {
|
|
|
1153
1166
|
url: urlStr,
|
|
1154
1167
|
requestId,
|
|
1155
1168
|
durationMs: Date.now() - startedAt,
|
|
1156
|
-
error: "network_error"
|
|
1169
|
+
error: err instanceof TopoloSdkError ? err.code : "network_error"
|
|
1157
1170
|
});
|
|
1158
1171
|
throw err;
|
|
1159
1172
|
}
|
|
@@ -2140,11 +2153,12 @@ function compactExample(input) {
|
|
|
2140
2153
|
function compactActionValidation(actionId, validation) {
|
|
2141
2154
|
return { actionId, valid: validation.valid, errors: validation.errors };
|
|
2142
2155
|
}
|
|
2143
|
-
var ACTION_RESULT_MAX_DEPTH =
|
|
2144
|
-
var ACTION_RESULT_MAX_KEYS =
|
|
2145
|
-
var
|
|
2146
|
-
var
|
|
2147
|
-
var
|
|
2156
|
+
var ACTION_RESULT_MAX_DEPTH = 3;
|
|
2157
|
+
var ACTION_RESULT_MAX_KEYS = 12;
|
|
2158
|
+
var ACTION_RESULT_MAX_ORDINARY_KEYS = 5;
|
|
2159
|
+
var ACTION_RESULT_MAX_ITEMS = 3;
|
|
2160
|
+
var ACTION_RESULT_MAX_SCALARS = 60;
|
|
2161
|
+
var ACTION_RESULT_MAX_STRING = 256;
|
|
2148
2162
|
function resultKeyPriority(key) {
|
|
2149
2163
|
if (/^(id|requestId|status|state|url|slug|name|title|version)$/i.test(key)) return 0;
|
|
2150
2164
|
if (/(Id|Ids|Url|Uri|Status|State|Count|Total|Version|CreatedAt|UpdatedAt)$/i.test(key)) return 1;
|
|
@@ -2170,7 +2184,14 @@ function compactResultValue(value, depth, budget) {
|
|
|
2170
2184
|
if (typeof value === "object") {
|
|
2171
2185
|
const record = value;
|
|
2172
2186
|
const allKeys = Object.keys(record);
|
|
2173
|
-
const
|
|
2187
|
+
const ranked = allKeys.sort((left, right) => resultKeyPriority(left) - resultKeyPriority(right));
|
|
2188
|
+
const prioritized = ranked.filter((key) => resultKeyPriority(key) < 2);
|
|
2189
|
+
const ordinary = ranked.filter((key) => resultKeyPriority(key) === 2);
|
|
2190
|
+
const ordinaryLimit = depth === 0 ? ACTION_RESULT_MAX_ORDINARY_KEYS : prioritized.length ? 1 : ACTION_RESULT_MAX_ORDINARY_KEYS;
|
|
2191
|
+
const keys = [
|
|
2192
|
+
...prioritized,
|
|
2193
|
+
...ordinary.slice(0, ordinaryLimit)
|
|
2194
|
+
].slice(0, ACTION_RESULT_MAX_KEYS);
|
|
2174
2195
|
const compact = Object.fromEntries(keys.map((key) => [key, compactResultValue(record[key], depth + 1, budget)]));
|
|
2175
2196
|
if (allKeys.length > keys.length) compact["_omittedKeys"] = allKeys.length - keys.length;
|
|
2176
2197
|
return compact;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topolo/sdk",
|
|
3
|
-
"version": "0.11.
|
|
4
|
-
"topoloPublishedVersion": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
|
+
"topoloPublishedVersion": "0.11.5",
|
|
5
5
|
"description": "Typed client SDK for the Topolo platform. Used by TopoloCli, TopoloMCP, and third-party agents.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"author": "Topolo",
|