@topolo/sdk 0.6.0 → 0.7.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.
@@ -22,8 +22,10 @@ var credential_store_exports = {};
22
22
  __export(credential_store_exports, {
23
23
  ENVIRONMENT_DEFAULT_SERVICE_URLS: () => ENVIRONMENT_DEFAULT_SERVICE_URLS,
24
24
  TOPOLO_ENVIRONMENTS: () => TOPOLO_ENVIRONMENTS,
25
+ activateContext: () => activateContext,
25
26
  clearProfileCredential: () => clearProfileCredential,
26
27
  configPath: () => configPath,
28
+ contextKey: () => contextKey,
27
29
  credentialSourceFromConfig: () => credentialSourceFromConfig,
28
30
  envVarPrefix: () => envVarPrefix,
29
31
  normalizeEnvironment: () => normalizeEnvironment,
@@ -36,6 +38,7 @@ __export(credential_store_exports, {
36
38
  resolvedProfileConfig: () => resolvedProfileConfig,
37
39
  selectedEnvironment: () => selectedEnvironment,
38
40
  writeConfig: () => writeConfig,
41
+ writeContextCredential: () => writeContextCredential,
39
42
  writeProfileConfig: () => writeProfileConfig
40
43
  });
41
44
  module.exports = __toCommonJS(credential_store_exports);
@@ -230,6 +233,9 @@ var TopoloOAuth = class {
230
233
 
231
234
  // src/node/credential-store.ts
232
235
  var TOPOLO_ENVIRONMENTS = ["production", "staging", "development", "local"];
236
+ function contextKey(contextType, organizationId) {
237
+ return contextType === "organization" && organizationId ? `org:${organizationId}` : "personal";
238
+ }
233
239
  var ENVIRONMENT_DEFAULT_SERVICE_URLS = {
234
240
  production: {
235
241
  developers: "https://developers.topolo.app"
@@ -323,6 +329,28 @@ function writeProfileConfig(config, environment, profile) {
323
329
  };
324
330
  return { ...config, profiles };
325
331
  }
332
+ function writeContextCredential(config, environment, ctx, makeActive = true) {
333
+ const key = contextKey(ctx.contextType, ctx.organizationId);
334
+ const profile = profileForEnvironment(config, environment);
335
+ const contexts = { ...profile.contexts ?? {}, [key]: ctx };
336
+ const next = { contexts };
337
+ if (makeActive) {
338
+ next.activeContext = key;
339
+ next.credential = ctx.credential;
340
+ next.oauthClientId = ctx.oauthClientId ?? profile.oauthClientId;
341
+ }
342
+ return writeProfileConfig(config, environment, next);
343
+ }
344
+ function activateContext(config, environment, key) {
345
+ const profile = profileForEnvironment(config, environment);
346
+ const ctx = profile.contexts?.[key];
347
+ if (!ctx) return config;
348
+ return writeProfileConfig(config, environment, {
349
+ activeContext: key,
350
+ credential: ctx.credential,
351
+ oauthClientId: ctx.oauthClientId ?? profile.oauthClientId
352
+ });
353
+ }
326
354
  function clearProfileCredential(config, environment) {
327
355
  const next = { ...config };
328
356
  if (environment === "production") {
@@ -422,8 +450,10 @@ function resolvedProfileConfig(config, environment = selectedEnvironment()) {
422
450
  0 && (module.exports = {
423
451
  ENVIRONMENT_DEFAULT_SERVICE_URLS,
424
452
  TOPOLO_ENVIRONMENTS,
453
+ activateContext,
425
454
  clearProfileCredential,
426
455
  configPath,
456
+ contextKey,
427
457
  credentialSourceFromConfig,
428
458
  envVarPrefix,
429
459
  normalizeEnvironment,
@@ -436,5 +466,6 @@ function resolvedProfileConfig(config, environment = selectedEnvironment()) {
436
466
  resolvedProfileConfig,
437
467
  selectedEnvironment,
438
468
  writeConfig,
469
+ writeContextCredential,
439
470
  writeProfileConfig
440
471
  });
@@ -50,7 +50,26 @@ interface TopoloEnvironmentProfile {
50
50
  oauthClientId?: string;
51
51
  serviceUrls?: Record<string, string>;
52
52
  agentName?: string;
53
+ /**
54
+ * The context (`personal` or `org:<orgId>`) whose credential is currently
55
+ * active. `credential` above always mirrors `contexts[activeContext]`, so
56
+ * credential resolution + the MCP keep working unchanged while `contexts`
57
+ * lets the CLI hold and switch between multiple org/personal contexts.
58
+ */
59
+ activeContext?: string;
60
+ contexts?: Record<string, TopoloContextCredential>;
53
61
  }
62
+ /** A signed-in context — personal, or a specific organization. */
63
+ interface TopoloContextCredential {
64
+ contextType: 'personal' | 'organization';
65
+ organizationId?: string;
66
+ organizationSlug?: string;
67
+ organizationName?: string;
68
+ credential?: TopoloCredential;
69
+ oauthClientId?: string;
70
+ }
71
+ /** Stable key for a context within a profile's `contexts` map. */
72
+ declare function contextKey(contextType: 'personal' | 'organization', organizationId?: string | null): string;
54
73
  /**
55
74
  * Default service URLs per environment. `local` has no baked defaults — a
56
75
  * local dev loop points services at ad-hoc ports, so it is driven entirely by
@@ -65,6 +84,14 @@ declare function selectedEnvironment(): TopoloEnvironment;
65
84
  declare function envVarPrefix(environment: TopoloEnvironment): string;
66
85
  declare function profileForEnvironment(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
67
86
  declare function writeProfileConfig(config: TopoloConfig, environment: TopoloEnvironment, profile: TopoloEnvironmentProfile): TopoloConfig;
87
+ /**
88
+ * Store a context's credential in the profile's `contexts` map. When
89
+ * `makeActive` (default), also point the profile's active credential at it so
90
+ * credential resolution + the MCP use this context.
91
+ */
92
+ declare function writeContextCredential(config: TopoloConfig, environment: TopoloEnvironment, ctx: TopoloContextCredential, makeActive?: boolean): TopoloConfig;
93
+ /** Point the profile's active credential at an already-stored context. */
94
+ declare function activateContext(config: TopoloConfig, environment: TopoloEnvironment, key: string): TopoloConfig;
68
95
  declare function clearProfileCredential(config: TopoloConfig, environment: TopoloEnvironment): TopoloConfig;
69
96
  declare function credentialSourceFromConfig(config: TopoloConfig, environment?: TopoloEnvironment): string;
70
97
  /**
@@ -78,4 +105,4 @@ declare function resolveAgentName(configAgentName?: string): string | undefined;
78
105
  declare function resolveServiceUrls(configUrls?: Record<string, string>, environment?: TopoloEnvironment): Record<string, string> | undefined;
79
106
  declare function resolvedProfileConfig(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
80
107
 
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 };
108
+ export { ENVIRONMENT_DEFAULT_SERVICE_URLS, TOPOLO_ENVIRONMENTS, type TopoloConfig, type TopoloContextCredential, type TopoloEnvironment, type TopoloEnvironmentProfile, activateContext, clearProfileCredential, configPath, contextKey, credentialSourceFromConfig, envVarPrefix, normalizeEnvironment, profileForEnvironment, readConfig, refreshCredentialIfNeeded, resolveAgentName, resolveCredential, resolveServiceUrls, resolvedProfileConfig, selectedEnvironment, writeConfig, writeContextCredential, writeProfileConfig };
@@ -50,7 +50,26 @@ interface TopoloEnvironmentProfile {
50
50
  oauthClientId?: string;
51
51
  serviceUrls?: Record<string, string>;
52
52
  agentName?: string;
53
+ /**
54
+ * The context (`personal` or `org:<orgId>`) whose credential is currently
55
+ * active. `credential` above always mirrors `contexts[activeContext]`, so
56
+ * credential resolution + the MCP keep working unchanged while `contexts`
57
+ * lets the CLI hold and switch between multiple org/personal contexts.
58
+ */
59
+ activeContext?: string;
60
+ contexts?: Record<string, TopoloContextCredential>;
53
61
  }
62
+ /** A signed-in context — personal, or a specific organization. */
63
+ interface TopoloContextCredential {
64
+ contextType: 'personal' | 'organization';
65
+ organizationId?: string;
66
+ organizationSlug?: string;
67
+ organizationName?: string;
68
+ credential?: TopoloCredential;
69
+ oauthClientId?: string;
70
+ }
71
+ /** Stable key for a context within a profile's `contexts` map. */
72
+ declare function contextKey(contextType: 'personal' | 'organization', organizationId?: string | null): string;
54
73
  /**
55
74
  * Default service URLs per environment. `local` has no baked defaults — a
56
75
  * local dev loop points services at ad-hoc ports, so it is driven entirely by
@@ -65,6 +84,14 @@ declare function selectedEnvironment(): TopoloEnvironment;
65
84
  declare function envVarPrefix(environment: TopoloEnvironment): string;
66
85
  declare function profileForEnvironment(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
67
86
  declare function writeProfileConfig(config: TopoloConfig, environment: TopoloEnvironment, profile: TopoloEnvironmentProfile): TopoloConfig;
87
+ /**
88
+ * Store a context's credential in the profile's `contexts` map. When
89
+ * `makeActive` (default), also point the profile's active credential at it so
90
+ * credential resolution + the MCP use this context.
91
+ */
92
+ declare function writeContextCredential(config: TopoloConfig, environment: TopoloEnvironment, ctx: TopoloContextCredential, makeActive?: boolean): TopoloConfig;
93
+ /** Point the profile's active credential at an already-stored context. */
94
+ declare function activateContext(config: TopoloConfig, environment: TopoloEnvironment, key: string): TopoloConfig;
68
95
  declare function clearProfileCredential(config: TopoloConfig, environment: TopoloEnvironment): TopoloConfig;
69
96
  declare function credentialSourceFromConfig(config: TopoloConfig, environment?: TopoloEnvironment): string;
70
97
  /**
@@ -78,4 +105,4 @@ declare function resolveAgentName(configAgentName?: string): string | undefined;
78
105
  declare function resolveServiceUrls(configUrls?: Record<string, string>, environment?: TopoloEnvironment): Record<string, string> | undefined;
79
106
  declare function resolvedProfileConfig(config: TopoloConfig, environment?: TopoloEnvironment): TopoloEnvironmentProfile;
80
107
 
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 };
108
+ export { ENVIRONMENT_DEFAULT_SERVICE_URLS, TOPOLO_ENVIRONMENTS, type TopoloConfig, type TopoloContextCredential, type TopoloEnvironment, type TopoloEnvironmentProfile, activateContext, clearProfileCredential, configPath, contextKey, credentialSourceFromConfig, envVarPrefix, normalizeEnvironment, profileForEnvironment, readConfig, refreshCredentialIfNeeded, resolveAgentName, resolveCredential, resolveServiceUrls, resolvedProfileConfig, selectedEnvironment, writeConfig, writeContextCredential, writeProfileConfig };
@@ -190,6 +190,9 @@ var TopoloOAuth = class {
190
190
 
191
191
  // src/node/credential-store.ts
192
192
  var TOPOLO_ENVIRONMENTS = ["production", "staging", "development", "local"];
193
+ function contextKey(contextType, organizationId) {
194
+ return contextType === "organization" && organizationId ? `org:${organizationId}` : "personal";
195
+ }
193
196
  var ENVIRONMENT_DEFAULT_SERVICE_URLS = {
194
197
  production: {
195
198
  developers: "https://developers.topolo.app"
@@ -283,6 +286,28 @@ function writeProfileConfig(config, environment, profile) {
283
286
  };
284
287
  return { ...config, profiles };
285
288
  }
289
+ function writeContextCredential(config, environment, ctx, makeActive = true) {
290
+ const key = contextKey(ctx.contextType, ctx.organizationId);
291
+ const profile = profileForEnvironment(config, environment);
292
+ const contexts = { ...profile.contexts ?? {}, [key]: ctx };
293
+ const next = { contexts };
294
+ if (makeActive) {
295
+ next.activeContext = key;
296
+ next.credential = ctx.credential;
297
+ next.oauthClientId = ctx.oauthClientId ?? profile.oauthClientId;
298
+ }
299
+ return writeProfileConfig(config, environment, next);
300
+ }
301
+ function activateContext(config, environment, key) {
302
+ const profile = profileForEnvironment(config, environment);
303
+ const ctx = profile.contexts?.[key];
304
+ if (!ctx) return config;
305
+ return writeProfileConfig(config, environment, {
306
+ activeContext: key,
307
+ credential: ctx.credential,
308
+ oauthClientId: ctx.oauthClientId ?? profile.oauthClientId
309
+ });
310
+ }
286
311
  function clearProfileCredential(config, environment) {
287
312
  const next = { ...config };
288
313
  if (environment === "production") {
@@ -381,8 +406,10 @@ function resolvedProfileConfig(config, environment = selectedEnvironment()) {
381
406
  export {
382
407
  ENVIRONMENT_DEFAULT_SERVICE_URLS,
383
408
  TOPOLO_ENVIRONMENTS,
409
+ activateContext,
384
410
  clearProfileCredential,
385
411
  configPath,
412
+ contextKey,
386
413
  credentialSourceFromConfig,
387
414
  envVarPrefix,
388
415
  normalizeEnvironment,
@@ -395,5 +422,6 @@ export {
395
422
  resolvedProfileConfig,
396
423
  selectedEnvironment,
397
424
  writeConfig,
425
+ writeContextCredential,
398
426
  writeProfileConfig
399
427
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topolo/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Typed client SDK for the Topolo platform. Used by TopoloCli, TopoloMCP, and third-party agents.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,6 +38,34 @@ export interface TopoloEnvironmentProfile {
38
38
  oauthClientId?: string;
39
39
  serviceUrls?: Record<string, string>;
40
40
  agentName?: string;
41
+ /**
42
+ * The context (`personal` or `org:<orgId>`) whose credential is currently
43
+ * active. `credential` above always mirrors `contexts[activeContext]`, so
44
+ * credential resolution + the MCP keep working unchanged while `contexts`
45
+ * lets the CLI hold and switch between multiple org/personal contexts.
46
+ */
47
+ activeContext?: string;
48
+ contexts?: Record<string, TopoloContextCredential>;
49
+ }
50
+
51
+ /** A signed-in context — personal, or a specific organization. */
52
+ export interface TopoloContextCredential {
53
+ contextType: 'personal' | 'organization';
54
+ organizationId?: string;
55
+ organizationSlug?: string;
56
+ organizationName?: string;
57
+ credential?: TopoloCredential;
58
+ oauthClientId?: string;
59
+ }
60
+
61
+ /** Stable key for a context within a profile's `contexts` map. */
62
+ export function contextKey(
63
+ contextType: 'personal' | 'organization',
64
+ organizationId?: string | null,
65
+ ): string {
66
+ return contextType === 'organization' && organizationId
67
+ ? `org:${organizationId}`
68
+ : 'personal';
41
69
  }
42
70
 
43
71
  /**
@@ -161,6 +189,45 @@ export function writeProfileConfig(
161
189
  return { ...config, profiles };
162
190
  }
163
191
 
192
+ /**
193
+ * Store a context's credential in the profile's `contexts` map. When
194
+ * `makeActive` (default), also point the profile's active credential at it so
195
+ * credential resolution + the MCP use this context.
196
+ */
197
+ export function writeContextCredential(
198
+ config: TopoloConfig,
199
+ environment: TopoloEnvironment,
200
+ ctx: TopoloContextCredential,
201
+ makeActive = true,
202
+ ): TopoloConfig {
203
+ const key = contextKey(ctx.contextType, ctx.organizationId);
204
+ const profile = profileForEnvironment(config, environment);
205
+ const contexts = { ...(profile.contexts ?? {}), [key]: ctx };
206
+ const next: TopoloEnvironmentProfile = { contexts };
207
+ if (makeActive) {
208
+ next.activeContext = key;
209
+ next.credential = ctx.credential;
210
+ next.oauthClientId = ctx.oauthClientId ?? profile.oauthClientId;
211
+ }
212
+ return writeProfileConfig(config, environment, next);
213
+ }
214
+
215
+ /** Point the profile's active credential at an already-stored context. */
216
+ export function activateContext(
217
+ config: TopoloConfig,
218
+ environment: TopoloEnvironment,
219
+ key: string,
220
+ ): TopoloConfig {
221
+ const profile = profileForEnvironment(config, environment);
222
+ const ctx = profile.contexts?.[key];
223
+ if (!ctx) return config;
224
+ return writeProfileConfig(config, environment, {
225
+ activeContext: key,
226
+ credential: ctx.credential,
227
+ oauthClientId: ctx.oauthClientId ?? profile.oauthClientId,
228
+ });
229
+ }
230
+
164
231
  export function clearProfileCredential(
165
232
  config: TopoloConfig,
166
233
  environment: TopoloEnvironment,