@topolo/sdk 0.6.0 → 0.8.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.
@@ -1,440 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/node/credential-store.ts
21
- var credential_store_exports = {};
22
- __export(credential_store_exports, {
23
- ENVIRONMENT_DEFAULT_SERVICE_URLS: () => ENVIRONMENT_DEFAULT_SERVICE_URLS,
24
- TOPOLO_ENVIRONMENTS: () => TOPOLO_ENVIRONMENTS,
25
- clearProfileCredential: () => clearProfileCredential,
26
- configPath: () => configPath,
27
- credentialSourceFromConfig: () => credentialSourceFromConfig,
28
- envVarPrefix: () => envVarPrefix,
29
- normalizeEnvironment: () => normalizeEnvironment,
30
- profileForEnvironment: () => profileForEnvironment,
31
- readConfig: () => readConfig,
32
- refreshCredentialIfNeeded: () => refreshCredentialIfNeeded,
33
- resolveAgentName: () => resolveAgentName,
34
- resolveCredential: () => resolveCredential,
35
- resolveServiceUrls: () => resolveServiceUrls,
36
- resolvedProfileConfig: () => resolvedProfileConfig,
37
- selectedEnvironment: () => selectedEnvironment,
38
- writeConfig: () => writeConfig,
39
- writeProfileConfig: () => writeProfileConfig
40
- });
41
- module.exports = __toCommonJS(credential_store_exports);
42
- var import_promises = require("fs/promises");
43
- var import_node_fs = require("fs");
44
- var import_node_os = require("os");
45
- var import_node_path = require("path");
46
-
47
- // src/errors.ts
48
- var TopoloSdkError = class extends Error {
49
- code;
50
- constructor(code, message) {
51
- super(message);
52
- this.name = "TopoloSdkError";
53
- this.code = code;
54
- }
55
- };
56
- var TopoloAuthError = class extends TopoloSdkError {
57
- constructor(message, code = "auth_error") {
58
- super(code, message);
59
- this.name = "TopoloAuthError";
60
- }
61
- };
62
- var TopoloHttpError = class extends TopoloSdkError {
63
- status;
64
- body;
65
- service;
66
- path;
67
- constructor(service, path, status, body, message) {
68
- super("http_error", message ?? `HTTP ${status} from ${service}${path}`);
69
- this.name = "TopoloHttpError";
70
- this.status = status;
71
- this.body = body;
72
- this.service = service;
73
- this.path = path;
74
- }
75
- };
76
-
77
- // src/services.generated.ts
78
- var APP_API_URLS = {
79
- agent: "https://agent.topolo.app",
80
- auth: "https://auth.topolo.app",
81
- backup: "https://backup.topolo.app",
82
- books: "https://books.topolo.app",
83
- bugfix: "https://bugfix.topolo.app",
84
- bytes: "https://bytes.topolo.app",
85
- calendar: "https://calendar.topolo.app",
86
- capacity: "https://capacity.topolo.app",
87
- chat: "https://chat.topolo.app",
88
- commerce: "https://commerce.topolo.app",
89
- compose: "https://compose.topolo.app",
90
- consent: "https://consent.topolo.app",
91
- crm: "https://crm.topolo.app",
92
- developers: "https://developers.topolo.app",
93
- director: "https://director.topolo.app",
94
- feed: "https://feed.topolo.app",
95
- flow: "https://flow.topolo.app",
96
- forecast: "https://forecast.topolo.app",
97
- forms: "https://forms.topolo.app",
98
- home: "https://home.topolo.app",
99
- insights: "https://insights.topolo.app",
100
- inventory: "https://inventory.topolo.app",
101
- learn: "https://learn.topolo.app",
102
- localize: "https://localize.topolo.app",
103
- mail: "https://mail.topolo.app",
104
- mdm: "https://mdm.topolo.app",
105
- messages: "https://messages.topolo.app",
106
- nexus: "https://nexus.topolo.app",
107
- notify: "https://notify.topolo.app",
108
- observability_watch: "https://observability-watch.topolo.app",
109
- one: "https://www.topolo.app",
110
- p2p: "https://p2p.topolo.app",
111
- pay: "https://pay.topolo.app",
112
- people: "https://people.topolo.app",
113
- "quro.api": "https://api.ol0.me",
114
- "quro.redirect": "https://ol0.me",
115
- roadmapper: "https://roadmapper.topolo.app",
116
- sign: "https://sign.topolo.app",
117
- social_studio: "https://studio.topolo.app",
118
- socialize: "https://socialize.topolo.app",
119
- spaces: "https://spaces.topolo.app",
120
- status: "https://status.topolo.app",
121
- success: "https://success.topolo.app",
122
- support: "https://support.topolo.app",
123
- survey: "https://survey.topolo.app",
124
- voice: "https://voice.topolo.app",
125
- web: "https://web.topolo.app"
126
- };
127
-
128
- // src/services.ts
129
- var DEFAULT_APP_URLS = APP_API_URLS;
130
- function resolveServiceUrl(service, overrides) {
131
- const override = resolveServiceUrlOverride([service], overrides);
132
- if (override) return override;
133
- return DEFAULT_APP_URLS[service];
134
- }
135
- function resolveServiceUrlOverride(keys, overrides) {
136
- for (const key of keys) {
137
- const direct = overrides?.[key];
138
- if (direct) return direct;
139
- const envStyleKey = key.replace(/\./g, "_");
140
- const envStyle = overrides?.[envStyleKey];
141
- if (envStyle) return envStyle;
142
- }
143
- for (const key of keys) {
144
- const envKey = `TOPOLO_APP_URL_${key.replace(/\./g, "_").toUpperCase()}`;
145
- const envValue = typeof process !== "undefined" ? process.env?.[envKey] : void 0;
146
- if (envValue) return envValue;
147
- }
148
- return null;
149
- }
150
-
151
- // src/oauth.ts
152
- var DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
153
- var TopoloOAuth = class {
154
- baseUrl;
155
- fetchImpl;
156
- constructor(options = {}) {
157
- this.baseUrl = resolveServiceUrl("auth", options.serviceUrls);
158
- this.fetchImpl = options.fetch ?? fetch;
159
- }
160
- /**
161
- * RFC 8628 device authorization grant — starts the flow by asking the server
162
- * for a device_code + user_code. The caller prints the user_code +
163
- * verification_uri and then polls `pollDeviceToken` until approval.
164
- */
165
- async requestDeviceCode(params) {
166
- const body = new URLSearchParams();
167
- body.set("client_id", params.clientId);
168
- if (params.scope) {
169
- body.set("scope", Array.isArray(params.scope) ? params.scope.join(" ") : params.scope);
170
- }
171
- return this.#postForm("/api/developer-oauth/device_authorization", body);
172
- }
173
- /**
174
- * Polls the token endpoint once. Returns the token pair on success, or
175
- * throws a `TopoloAuthError` whose `code` is one of the RFC 8628 poll
176
- * states: `authorization_pending`, `slow_down`, `access_denied`,
177
- * `expired_token`. Callers should back off on `slow_down`, wait at least
178
- * one `interval` on `authorization_pending`, and give up on the rest.
179
- */
180
- async pollDeviceToken(params) {
181
- const body = new URLSearchParams();
182
- body.set("grant_type", DEVICE_GRANT);
183
- body.set("client_id", params.clientId);
184
- body.set("device_code", params.deviceCode);
185
- if (params.clientSecret) body.set("client_secret", params.clientSecret);
186
- return this.#postForm("/api/developer-oauth/token", body);
187
- }
188
- /** Exchange an authorization code (with PKCE) for tokens. */
189
- async exchangeAuthorizationCode(params) {
190
- const body = new URLSearchParams();
191
- body.set("grant_type", "authorization_code");
192
- body.set("client_id", params.clientId);
193
- body.set("code", params.code);
194
- body.set("redirect_uri", params.redirectUri);
195
- if (params.codeVerifier) body.set("code_verifier", params.codeVerifier);
196
- if (params.clientSecret) body.set("client_secret", params.clientSecret);
197
- return this.#postForm("/api/developer-oauth/token", body);
198
- }
199
- /** Rotate a refresh token for a new token pair. */
200
- async refreshToken(params) {
201
- const body = new URLSearchParams();
202
- body.set("grant_type", "refresh_token");
203
- body.set("client_id", params.clientId);
204
- body.set("refresh_token", params.refreshToken);
205
- if (params.clientSecret) body.set("client_secret", params.clientSecret);
206
- return this.#postForm("/api/developer-oauth/token", body);
207
- }
208
- async #postForm(path, body) {
209
- const url = new URL(path, this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`);
210
- const res = await this.fetchImpl(url.toString(), {
211
- method: "POST",
212
- headers: {
213
- "Content-Type": "application/x-www-form-urlencoded",
214
- Accept: "application/json"
215
- },
216
- body: body.toString()
217
- });
218
- const contentType = res.headers.get("Content-Type") ?? "";
219
- const parsed = contentType.includes("application/json") ? await res.json().catch(() => null) : await res.text().catch(() => null);
220
- if (!res.ok) {
221
- if (parsed && typeof parsed === "object" && "error" in parsed) {
222
- const err = parsed;
223
- throw new TopoloAuthError(err.error_description || err.error, err.error);
224
- }
225
- throw new TopoloHttpError("auth", path, res.status, parsed);
226
- }
227
- return parsed;
228
- }
229
- };
230
-
231
- // src/node/credential-store.ts
232
- var TOPOLO_ENVIRONMENTS = ["production", "staging", "development", "local"];
233
- var ENVIRONMENT_DEFAULT_SERVICE_URLS = {
234
- production: {
235
- developers: "https://developers.topolo.app"
236
- },
237
- staging: {
238
- auth: "https://auth.stg.topolo.us",
239
- developers: "https://developers.stg.topolo.us",
240
- seed: "https://seed.stg.topolo.us"
241
- },
242
- development: {
243
- auth: "https://auth.topolo.dev",
244
- developers: "https://developers.topolo.dev"
245
- },
246
- local: {}
247
- };
248
- function configPath() {
249
- const override = process.env.TOPOLO_CONFIG_PATH;
250
- if (override) return override;
251
- const base = process.env.XDG_CONFIG_HOME || ((0, import_node_os.platform)() === "win32" ? (0, import_node_path.join)((0, import_node_os.homedir)(), "AppData", "Roaming") : (0, import_node_path.join)((0, import_node_os.homedir)(), ".config"));
252
- return (0, import_node_path.join)(base, "topolo", "config.json");
253
- }
254
- async function readConfig() {
255
- const path = configPath();
256
- if (!(0, import_node_fs.existsSync)(path)) return {};
257
- try {
258
- const raw = await (0, import_promises.readFile)(path, "utf8");
259
- return JSON.parse(raw);
260
- } catch {
261
- return {};
262
- }
263
- }
264
- async function writeConfig(config) {
265
- const path = configPath();
266
- await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
267
- await (0, import_promises.writeFile)(path, JSON.stringify(config, null, 2) + "\n", "utf8");
268
- if ((0, import_node_os.platform)() !== "win32") {
269
- try {
270
- await (0, import_promises.chmod)(path, 384);
271
- } catch {
272
- }
273
- }
274
- }
275
- function normalizeEnvironment(value) {
276
- const normalized = (value ?? "production").trim().toLowerCase();
277
- if (normalized === "" || normalized === "production" || normalized === "prod") {
278
- return "production";
279
- }
280
- if (normalized === "staging" || normalized === "stage" || normalized === "stg") {
281
- return "staging";
282
- }
283
- if (normalized === "development" || normalized === "dev") {
284
- return "development";
285
- }
286
- if (normalized === "local" || normalized === "localhost") {
287
- return "local";
288
- }
289
- throw new Error(
290
- `Unknown Topolo environment "${value}". Expected production, staging, development, or local.`
291
- );
292
- }
293
- function selectedEnvironment() {
294
- return normalizeEnvironment(process.env.TOPOLO_ENV);
295
- }
296
- function envVarPrefix(environment) {
297
- if (environment === "production") return "TOPOLO_PRODUCTION";
298
- if (environment === "staging") return "TOPOLO_STAGING";
299
- if (environment === "development") return "TOPOLO_DEVELOPMENT";
300
- return "TOPOLO_LOCAL";
301
- }
302
- function profileForEnvironment(config, environment = selectedEnvironment()) {
303
- const profile = config.profiles?.[environment] ?? {};
304
- if (environment === "production") {
305
- return {
306
- credential: config.credential,
307
- oauthClientId: config.oauthClientId,
308
- ...profile,
309
- serviceUrls: {
310
- ...config.serviceUrls ?? {},
311
- ...profile.serviceUrls ?? {}
312
- },
313
- agentName: profile.agentName ?? config.agentName
314
- };
315
- }
316
- return profile;
317
- }
318
- function writeProfileConfig(config, environment, profile) {
319
- const profiles = { ...config.profiles ?? {} };
320
- profiles[environment] = {
321
- ...profiles[environment] ?? {},
322
- ...profile
323
- };
324
- return { ...config, profiles };
325
- }
326
- function clearProfileCredential(config, environment) {
327
- const next = { ...config };
328
- if (environment === "production") {
329
- delete next.credential;
330
- delete next.oauthClientId;
331
- }
332
- const profiles = { ...config.profiles ?? {} };
333
- const profile = { ...profiles[environment] ?? {} };
334
- delete profile.credential;
335
- delete profile.oauthClientId;
336
- profiles[environment] = profile;
337
- return { ...next, profiles };
338
- }
339
- function credentialSourceFromConfig(config, environment = selectedEnvironment()) {
340
- const prefix = envVarPrefix(environment);
341
- if (process.env[`${prefix}_API_KEY`]) return `env:${prefix}_API_KEY`;
342
- if (process.env[`${prefix}_ACCESS_TOKEN`]) return `env:${prefix}_ACCESS_TOKEN`;
343
- if (process.env.TOPOLO_API_KEY) return "env:TOPOLO_API_KEY";
344
- if (process.env.TOPOLO_ACCESS_TOKEN) return "env:TOPOLO_ACCESS_TOKEN";
345
- return profileForEnvironment(config, environment).credential ? "config-file" : "none";
346
- }
347
- async function resolveCredential(environment = selectedEnvironment()) {
348
- const prefix = envVarPrefix(environment);
349
- const apiKey = process.env[`${prefix}_API_KEY`] ?? process.env.TOPOLO_API_KEY;
350
- if (apiKey) return { kind: "api_key", apiKey };
351
- const accessToken = process.env[`${prefix}_ACCESS_TOKEN`] ?? process.env.TOPOLO_ACCESS_TOKEN;
352
- if (accessToken) return { kind: "access_token", accessToken };
353
- const config = await readConfig();
354
- return profileForEnvironment(config, environment).credential ?? null;
355
- }
356
- var REFRESH_SKEW_SECONDS = 60;
357
- async function refreshCredentialIfNeeded(environment = selectedEnvironment()) {
358
- const prefix = envVarPrefix(environment);
359
- if (process.env[`${prefix}_API_KEY`] || process.env[`${prefix}_ACCESS_TOKEN`] || process.env.TOPOLO_API_KEY || process.env.TOPOLO_ACCESS_TOKEN) {
360
- return resolveCredential(environment);
361
- }
362
- const config = await readConfig();
363
- const profile = profileForEnvironment(config, environment);
364
- const cred = profile.credential;
365
- if (!cred || cred.kind !== "access_token") return cred ?? null;
366
- if (!cred.refreshToken || !cred.expiresAt || !profile.oauthClientId) return cred;
367
- const now = Math.floor(Date.now() / 1e3);
368
- if (cred.expiresAt - REFRESH_SKEW_SECONDS > now) return cred;
369
- try {
370
- const oauth = new TopoloOAuth({
371
- serviceUrls: resolveServiceUrls(profile.serviceUrls, environment)
372
- });
373
- const tokens = await oauth.refreshToken({
374
- clientId: profile.oauthClientId,
375
- refreshToken: cred.refreshToken
376
- });
377
- const refreshed = {
378
- kind: "access_token",
379
- accessToken: tokens.access_token,
380
- ...tokens.refresh_token ? { refreshToken: tokens.refresh_token } : { refreshToken: cred.refreshToken },
381
- expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
382
- };
383
- await writeConfig(
384
- environment === "production" && !config.profiles?.production ? { ...config, credential: refreshed } : writeProfileConfig(config, environment, { credential: refreshed })
385
- );
386
- return refreshed;
387
- } catch {
388
- return cred;
389
- }
390
- }
391
- function resolveAgentName(configAgentName) {
392
- return process.env.TOPOLO_AGENT_NAME ?? configAgentName;
393
- }
394
- function resolveServiceUrls(configUrls, environment = selectedEnvironment()) {
395
- const merged = {
396
- ...ENVIRONMENT_DEFAULT_SERVICE_URLS[environment],
397
- ...configUrls ?? {}
398
- };
399
- const prefix = `${envVarPrefix(environment)}_SERVICE_URL_`;
400
- for (const [k, v] of Object.entries(process.env)) {
401
- if (k.startsWith(prefix) && v) {
402
- merged[k.slice(prefix.length).toLowerCase()] = v;
403
- }
404
- }
405
- for (const [k, v] of Object.entries(process.env)) {
406
- if (k.startsWith("TOPOLO_SERVICE_URL_") && v) {
407
- merged[k.slice("TOPOLO_SERVICE_URL_".length).toLowerCase()] = v;
408
- }
409
- }
410
- return Object.keys(merged).length > 0 ? merged : void 0;
411
- }
412
- function resolvedProfileConfig(config, environment = selectedEnvironment()) {
413
- const profile = profileForEnvironment(config, environment);
414
- return {
415
- credential: profile.credential,
416
- oauthClientId: profile.oauthClientId,
417
- agentName: profile.agentName,
418
- serviceUrls: resolveServiceUrls(profile.serviceUrls, environment)
419
- };
420
- }
421
- // Annotate the CommonJS export names for ESM import in node:
422
- 0 && (module.exports = {
423
- ENVIRONMENT_DEFAULT_SERVICE_URLS,
424
- TOPOLO_ENVIRONMENTS,
425
- clearProfileCredential,
426
- configPath,
427
- credentialSourceFromConfig,
428
- envVarPrefix,
429
- normalizeEnvironment,
430
- profileForEnvironment,
431
- readConfig,
432
- refreshCredentialIfNeeded,
433
- resolveAgentName,
434
- resolveCredential,
435
- resolveServiceUrls,
436
- resolvedProfileConfig,
437
- selectedEnvironment,
438
- writeConfig,
439
- writeProfileConfig
440
- });
@@ -1,81 +0,0 @@
1
- /**
2
- * Auth credential types used by the SDK.
3
- *
4
- * Phase 1 supports two modes:
5
- * - `api_key`: a single platform API key (service-scoped at issuance).
6
- * Preferred for long-lived agent installs.
7
- * - `access_token`: a short-lived JWT from the interactive login flow.
8
- * Used by TopoloCli after `topolo auth login`.
9
- *
10
- * Phase 2 will add OAuth access tokens issued by the authorization-code +
11
- * PKCE flow in TopoloAuth. Those will plug in as a third variant.
12
- */
13
- type TopoloCredential = {
14
- kind: 'api_key';
15
- apiKey: string;
16
- } | {
17
- kind: 'access_token';
18
- accessToken: string;
19
- refreshToken?: string;
20
- expiresAt?: number;
21
- };
22
-
23
- /**
24
- * Node-only credential store shared by the `topolo` CLI and `@topolo/mcp`.
25
- *
26
- * Both need to read (and refresh) the credential that `topolo auth login`
27
- * writes to `$XDG_CONFIG_HOME/topolo/config.json`. This lives in a Node-only
28
- * subpath (`@topolo/sdk/node`) so the isomorphic SDK core never imports
29
- * `node:fs` — importing this module in a browser/worker bundle is a mistake.
30
- *
31
- * The CLI re-exports every symbol here from `packages/topolo-cli/src/config.ts`
32
- * so existing call sites are unchanged; the MCP imports it directly to fall
33
- * back to the on-disk credential when no `TOPOLO_*` env credential is set.
34
- */
35
- declare const TOPOLO_ENVIRONMENTS: readonly ["production", "staging", "development", "local"];
36
- type TopoloEnvironment = (typeof TOPOLO_ENVIRONMENTS)[number];
37
- interface TopoloConfig {
38
- credential?: TopoloCredential;
39
- /** OAuth client_id used for the most recent login — needed to refresh the access token. */
40
- oauthClientId?: string;
41
- /** Per-service URL overrides — written when user runs `topolo config set-url`. */
42
- serviceUrls?: Record<string, string>;
43
- /** Optional agent label propagated as `X-Topolo-Agent`. */
44
- agentName?: string;
45
- /** Environment-scoped profiles. Legacy top-level fields are treated as production. */
46
- profiles?: Partial<Record<TopoloEnvironment, TopoloEnvironmentProfile>>;
47
- }
48
- interface TopoloEnvironmentProfile {
49
- credential?: TopoloCredential;
50
- oauthClientId?: string;
51
- serviceUrls?: Record<string, string>;
52
- agentName?: string;
53
- }
54
- /**
55
- * Default service URLs per environment. `local` has no baked defaults — a
56
- * local dev loop points services at ad-hoc ports, so it is driven entirely by
57
- * `TOPOLO_LOCAL_SERVICE_URL_*` / `TOPOLO_SERVICE_URL_*` overrides.
58
- */
59
- declare const ENVIRONMENT_DEFAULT_SERVICE_URLS: Record<TopoloEnvironment, Record<string, string>>;
60
- declare function configPath(): string;
61
- declare function readConfig(): Promise<TopoloConfig>;
62
- declare function writeConfig(config: TopoloConfig): Promise<void>;
63
- declare function normalizeEnvironment(value: string | undefined): TopoloEnvironment;
64
- declare function selectedEnvironment(): TopoloEnvironment;
65
- declare function envVarPrefix(environment: TopoloEnvironment): string;
66
- declare function profileForEnvironment(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
67
- declare function writeProfileConfig(config: TopoloConfig, environment: TopoloEnvironment, profile: TopoloEnvironmentProfile): TopoloConfig;
68
- declare function clearProfileCredential(config: TopoloConfig, environment: TopoloEnvironment): TopoloConfig;
69
- declare function credentialSourceFromConfig(config: TopoloConfig, environment?: TopoloEnvironment): string;
70
- /**
71
- * Resolve credentials with env-var precedence over on-disk config.
72
- * Env vars are what agents set in their environment; config is what
73
- * interactive users get after running `topolo auth login`.
74
- */
75
- declare function resolveCredential(environment?: TopoloEnvironment): Promise<TopoloCredential | null>;
76
- declare function refreshCredentialIfNeeded(environment?: TopoloEnvironment): Promise<TopoloCredential | null>;
77
- declare function resolveAgentName(configAgentName?: string): string | undefined;
78
- declare function resolveServiceUrls(configUrls?: Record<string, string>, environment?: TopoloEnvironment): Record<string, string> | undefined;
79
- declare function resolvedProfileConfig(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
80
-
81
- export { ENVIRONMENT_DEFAULT_SERVICE_URLS, TOPOLO_ENVIRONMENTS, type TopoloConfig, type TopoloEnvironment, type TopoloEnvironmentProfile, clearProfileCredential, configPath, credentialSourceFromConfig, envVarPrefix, normalizeEnvironment, profileForEnvironment, readConfig, refreshCredentialIfNeeded, resolveAgentName, resolveCredential, resolveServiceUrls, resolvedProfileConfig, selectedEnvironment, writeConfig, writeProfileConfig };
@@ -1,81 +0,0 @@
1
- /**
2
- * Auth credential types used by the SDK.
3
- *
4
- * Phase 1 supports two modes:
5
- * - `api_key`: a single platform API key (service-scoped at issuance).
6
- * Preferred for long-lived agent installs.
7
- * - `access_token`: a short-lived JWT from the interactive login flow.
8
- * Used by TopoloCli after `topolo auth login`.
9
- *
10
- * Phase 2 will add OAuth access tokens issued by the authorization-code +
11
- * PKCE flow in TopoloAuth. Those will plug in as a third variant.
12
- */
13
- type TopoloCredential = {
14
- kind: 'api_key';
15
- apiKey: string;
16
- } | {
17
- kind: 'access_token';
18
- accessToken: string;
19
- refreshToken?: string;
20
- expiresAt?: number;
21
- };
22
-
23
- /**
24
- * Node-only credential store shared by the `topolo` CLI and `@topolo/mcp`.
25
- *
26
- * Both need to read (and refresh) the credential that `topolo auth login`
27
- * writes to `$XDG_CONFIG_HOME/topolo/config.json`. This lives in a Node-only
28
- * subpath (`@topolo/sdk/node`) so the isomorphic SDK core never imports
29
- * `node:fs` — importing this module in a browser/worker bundle is a mistake.
30
- *
31
- * The CLI re-exports every symbol here from `packages/topolo-cli/src/config.ts`
32
- * so existing call sites are unchanged; the MCP imports it directly to fall
33
- * back to the on-disk credential when no `TOPOLO_*` env credential is set.
34
- */
35
- declare const TOPOLO_ENVIRONMENTS: readonly ["production", "staging", "development", "local"];
36
- type TopoloEnvironment = (typeof TOPOLO_ENVIRONMENTS)[number];
37
- interface TopoloConfig {
38
- credential?: TopoloCredential;
39
- /** OAuth client_id used for the most recent login — needed to refresh the access token. */
40
- oauthClientId?: string;
41
- /** Per-service URL overrides — written when user runs `topolo config set-url`. */
42
- serviceUrls?: Record<string, string>;
43
- /** Optional agent label propagated as `X-Topolo-Agent`. */
44
- agentName?: string;
45
- /** Environment-scoped profiles. Legacy top-level fields are treated as production. */
46
- profiles?: Partial<Record<TopoloEnvironment, TopoloEnvironmentProfile>>;
47
- }
48
- interface TopoloEnvironmentProfile {
49
- credential?: TopoloCredential;
50
- oauthClientId?: string;
51
- serviceUrls?: Record<string, string>;
52
- agentName?: string;
53
- }
54
- /**
55
- * Default service URLs per environment. `local` has no baked defaults — a
56
- * local dev loop points services at ad-hoc ports, so it is driven entirely by
57
- * `TOPOLO_LOCAL_SERVICE_URL_*` / `TOPOLO_SERVICE_URL_*` overrides.
58
- */
59
- declare const ENVIRONMENT_DEFAULT_SERVICE_URLS: Record<TopoloEnvironment, Record<string, string>>;
60
- declare function configPath(): string;
61
- declare function readConfig(): Promise<TopoloConfig>;
62
- declare function writeConfig(config: TopoloConfig): Promise<void>;
63
- declare function normalizeEnvironment(value: string | undefined): TopoloEnvironment;
64
- declare function selectedEnvironment(): TopoloEnvironment;
65
- declare function envVarPrefix(environment: TopoloEnvironment): string;
66
- declare function profileForEnvironment(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
67
- declare function writeProfileConfig(config: TopoloConfig, environment: TopoloEnvironment, profile: TopoloEnvironmentProfile): TopoloConfig;
68
- declare function clearProfileCredential(config: TopoloConfig, environment: TopoloEnvironment): TopoloConfig;
69
- declare function credentialSourceFromConfig(config: TopoloConfig, environment?: TopoloEnvironment): string;
70
- /**
71
- * Resolve credentials with env-var precedence over on-disk config.
72
- * Env vars are what agents set in their environment; config is what
73
- * interactive users get after running `topolo auth login`.
74
- */
75
- declare function resolveCredential(environment?: TopoloEnvironment): Promise<TopoloCredential | null>;
76
- declare function refreshCredentialIfNeeded(environment?: TopoloEnvironment): Promise<TopoloCredential | null>;
77
- declare function resolveAgentName(configAgentName?: string): string | undefined;
78
- declare function resolveServiceUrls(configUrls?: Record<string, string>, environment?: TopoloEnvironment): Record<string, string> | undefined;
79
- declare function resolvedProfileConfig(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
80
-
81
- export { ENVIRONMENT_DEFAULT_SERVICE_URLS, TOPOLO_ENVIRONMENTS, type TopoloConfig, type TopoloEnvironment, type TopoloEnvironmentProfile, clearProfileCredential, configPath, credentialSourceFromConfig, envVarPrefix, normalizeEnvironment, profileForEnvironment, readConfig, refreshCredentialIfNeeded, resolveAgentName, resolveCredential, resolveServiceUrls, resolvedProfileConfig, selectedEnvironment, writeConfig, writeProfileConfig };