@aiam/ciba 0.9.8 → 0.9.9

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.
Files changed (3) hide show
  1. package/ciba.mjs +9 -3
  2. package/package.json +1 -1
  3. package/token.mjs +16 -16
package/ciba.mjs CHANGED
@@ -289,8 +289,11 @@ async function runCodeFlow(serverUrl, code, opts) {
289
289
 
290
290
  log('→ Exchanging code...');
291
291
 
292
- // Wait for the default destination token to land via resources map.
293
- const defaultResource = process.env.CIBA_DEFAULT_RESOURCE || 'webagents';
292
+ // Wait for the default destination token resolve from server options.
293
+ const optionsMap2 = deviceDoc.getMap('options');
294
+ const srvRes2 = optionsMap2.get('resources') ?? {};
295
+ const defaultResource = Object.keys(srvRes2).find(n => srvRes2[n]?.default)
296
+ ?? process.env.CIBA_DEFAULT_RESOURCE ?? 'webagents';
294
297
  const resourcesMap = deviceDoc.getMap('resources');
295
298
 
296
299
  const tokenMapName = await firstInYMap(resourcesMap, () => true, TIMEOUT)
@@ -438,7 +441,10 @@ function startDaemon(provider, deviceDoc, privateKey, serverUrl) {
438
441
  dlog(`${req.command} cmd attrs=${JSON.stringify(req.attrs)}`);
439
442
  const requests = deviceDoc.getMap('requests');
440
443
  const resourcesMap = deviceDoc.getMap('resources');
441
- const defaultResource = process.env.CIBA_DEFAULT_RESOURCE || 'webagents';
444
+ const optionsMap = deviceDoc.getMap('options');
445
+ const serverResources = optionsMap.get('resources') ?? {};
446
+ const defaultResource = Object.keys(serverResources).find(n => serverResources[n]?.default)
447
+ ?? process.env.CIBA_DEFAULT_RESOURCE ?? 'webagents';
442
448
  const attrs = { ...(req.attrs || {}) };
443
449
  const requestedResource = attrs.resource ?? defaultResource;
444
450
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiam/ciba",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "OAuth 2.0 Device Authorization Grant CLI with cross-device push approval (Yjs sync, ECDH-encrypted token delivery, persistent device id)",
5
5
  "type": "module",
6
6
  "bin": {
package/token.mjs CHANGED
@@ -30,7 +30,7 @@ const args = process.argv.slice(2);
30
30
  const get = (flag) => { const i = args.indexOf(flag); return i !== -1 ? args[i + 1] : undefined; };
31
31
  const has = (flag) => args.includes(flag);
32
32
 
33
- const resource = get('--resource') ?? process.env.CIBA_DEFAULT_RESOURCE ?? 'webagents';
33
+ const resource = get('--resource') ?? null; // null = resolve from server options after sync
34
34
  const jsonOut = has('--json');
35
35
  const envOut = has('--env');
36
36
  const isRefresh = has('--refresh');
@@ -179,25 +179,25 @@ if (meta.get('public_key') !== publicKey) meta.set('public_key', publicKey);
179
179
  const resourcesMap = deviceDoc.getMap('resources');
180
180
  const optionsMap = deviceDoc.getMap('options');
181
181
 
182
- // Read server options — resolve short name or use as-is.
183
- // options.resources = { webagents: { default: true, ... }, a2a: { ... }, ... }
182
+ // Read server options — resolve resource name.
183
+ // options.resources = { webagents: { default: true }, a2a: { ... }, ... }
184
184
  const serverResources = optionsMap.get('resources') ?? {};
185
185
  const resourceNames = Object.keys(serverResources);
186
186
 
187
- // Resolve the requested resource:
188
- // 1. If resource matches a short name directly → use it
189
- // 2. If resource is a URN → use it as-is
190
- // 3. If no resource → use default from options
191
- let resolvedResource = resource;
192
- if (!resource.includes(':') && !resourceNames.includes(resource)) {
193
- // Try to find a match case-insensitively
194
- const match = resourceNames.find(n => n.toLowerCase() === resource.toLowerCase());
195
- if (match) resolvedResource = match;
196
- }
197
- if (!resource) {
198
- // Use default
187
+ // Resolve:
188
+ // 1. --resource passed and matches a known short name → use it
189
+ // 2. --resource passed as URN → use as-is
190
+ // 3. No --resource → use server default (options.resources[name].default === true)
191
+ // 4. Fallback: first resource name, or 'webagents'
192
+ let resolvedResource;
193
+ if (resource) {
194
+ // Exact match or case-insensitive short name
195
+ const match = resourceNames.find(n => n === resource || n.toLowerCase() === resource.toLowerCase());
196
+ resolvedResource = match ?? resource; // fall back to as-is (URN or unknown)
197
+ } else {
198
+ // Use server default
199
199
  const def = resourceNames.find(n => serverResources[n]?.default);
200
- resolvedResource = def ?? resource;
200
+ resolvedResource = def ?? resourceNames[0] ?? 'webagents';
201
201
  }
202
202
 
203
203
  log(`→ options: ${JSON.stringify(serverResources)}`);