@meistrari/tela-cli 1.9.1 → 1.9.3

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.
@@ -0,0 +1,11 @@
1
+ import type { CredentialAdapter, ResolvedContext, StoredCredential } from '@meistrari/tela-local-config';
2
+ export declare function refreshCliSession(resolved: ResolvedContext, original: StoredCredential, credentials: CredentialAdapter, options?: {
3
+ platform?: string;
4
+ requestRefresh?: (contextId: string) => Promise<void>;
5
+ }): Promise<StoredCredential>;
6
+ export declare function renewThroughDock(contextId: string, dependencies?: {
7
+ available?: () => Promise<boolean>;
8
+ launch?: () => Promise<void>;
9
+ refresh?: (contextId: string) => Promise<void>;
10
+ wait?: () => Promise<void>;
11
+ }): Promise<void>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.refreshCliSession = refreshCliSession;
4
+ exports.renewThroughDock = renewThroughDock;
5
+ const node_child_process_1 = require("node:child_process");
6
+ const promises_1 = require("node:timers/promises");
7
+ const node_util_1 = require("node:util");
8
+ const tela_local_config_1 = require("@meistrari/tela-local-config");
9
+ async function refreshCliSession(resolved, original, credentials, options = {}) {
10
+ if (!(0, tela_local_config_1.shouldRefreshUserSession)(original))
11
+ return original;
12
+ const ref = resolved.context.credentialRef;
13
+ if ((options.platform ?? process.platform) !== 'darwin' || ref.provider !== 'keychain')
14
+ return await (0, tela_local_config_1.refreshUserSessionCredential)(resolved.environment, ref, original, credentials);
15
+ // Never rotate a macOS Keychain session in the CLI. Sandbox writes may fail
16
+ // AFTER the auth server consumes the old refresh token.
17
+ await (options.requestRefresh ?? renewThroughDock)(resolved.id);
18
+ const credential = await credentials.get(ref);
19
+ if (!credential || credential.kind !== 'user-session' || !credential.accessToken || (0, tela_local_config_1.isExpired)(credential))
20
+ throw new Error('Tela Dock did not save a valid session. Check the context in Dock and sign in again.');
21
+ return credential;
22
+ }
23
+ async function renewThroughDock(contextId, dependencies = {}) {
24
+ const available = dependencies.available ?? tela_local_config_1.isDockSessionBrokerAvailable;
25
+ if (!await available()) {
26
+ try {
27
+ await (dependencies.launch ?? launchDock)();
28
+ }
29
+ catch {
30
+ throw new tela_local_config_1.SessionBrokerUnavailableError();
31
+ }
32
+ let ready = false;
33
+ for (let attempt = 0; attempt < 20; attempt++) {
34
+ if (await available()) {
35
+ ready = true;
36
+ break;
37
+ }
38
+ await (dependencies.wait ?? (async () => await (0, promises_1.setTimeout)(250)))();
39
+ }
40
+ if (!ready)
41
+ throw new tela_local_config_1.SessionBrokerUnavailableError();
42
+ }
43
+ // Probe/launch retries above are read-only. Never replay a submitted renewal.
44
+ await (dependencies.refresh ?? tela_local_config_1.requestDockSessionRefresh)(contextId);
45
+ }
46
+ async function launchDock() {
47
+ await (0, node_util_1.promisify)(node_child_process_1.execFile)('/usr/bin/open', ['-g', '-b', 'com.tela.dock'], { timeout: 5000 });
48
+ }
package/dist/session.js CHANGED
@@ -4,6 +4,7 @@ exports.loadPantry = loadPantry;
4
4
  exports.loadPantryForContext = loadPantryForContext;
5
5
  exports.loadSession = loadSession;
6
6
  exports.resolvePantryBaseUrl = resolvePantryBaseUrl;
7
+ const refresh_session_1 = require("./refresh-session");
7
8
  const tela_local_config_1 = require("@meistrari/tela-local-config");
8
9
  const tela_pantry_1 = require("@meistrari/tela-pantry");
9
10
  const credentials_1 = require("./credentials");
@@ -41,8 +42,9 @@ async function loadPantryCredential(config, selected) {
41
42
  const originalCredential = await credentials.get(candidate.credentialRef);
42
43
  if (!originalCredential)
43
44
  continue;
45
+ const sessionContext = { ...candidate.resolved, context: { ...candidate.resolved.context, credentialRef: candidate.credentialRef } };
44
46
  const credential = originalCredential.kind === 'user-session'
45
- ? await (0, tela_local_config_1.refreshUserSessionCredential)(candidate.resolved.environment, candidate.credentialRef, originalCredential, credentials)
47
+ ? await (0, refresh_session_1.refreshCliSession)(sessionContext, originalCredential, credentials)
46
48
  : originalCredential;
47
49
  if (credential.accessToken)
48
50
  return credential;
@@ -91,7 +93,7 @@ async function loadSession(contextId, environmentId) {
91
93
  if (!originalCredential)
92
94
  throw new Error(`Missing credential for Tela context ${resolved.id}`);
93
95
  const credential = originalCredential.kind === 'user-session'
94
- ? await (0, tela_local_config_1.refreshUserSessionCredential)(resolved.environment, credentialRef, originalCredential, credentials)
96
+ ? await (0, refresh_session_1.refreshCliSession)(resolved, originalCredential, credentials)
95
97
  : originalCredential;
96
98
  return {
97
99
  resolved,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/tela-cli",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "Tela command line tools for local state and agent workflows.",
5
5
  "engines": {
6
6
  "node": ">=22"