@aiam/ciba 0.9.1 → 0.9.2
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/package.json +1 -1
- package/token.mjs +31 -9
package/package.json
CHANGED
package/token.mjs
CHANGED
|
@@ -106,16 +106,38 @@ function decrypt(map) {
|
|
|
106
106
|
// ─── tryGet ───────────────────────────────────────────────────────────────────
|
|
107
107
|
|
|
108
108
|
function tryGet(resourcesMap, deviceDoc, res) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
// Try the exact key first, then try known aliases.
|
|
110
|
+
const aliases = res ? [res] : [];
|
|
111
|
+
// If short name, also try known URN forms.
|
|
112
|
+
if (res && !res.includes(':')) {
|
|
113
|
+
// Read aliases from options if available (future: server can provide)
|
|
114
|
+
const opts = deviceDoc.getMap('options').get('resources') ?? {};
|
|
115
|
+
const meta = opts[res] ?? {};
|
|
116
|
+
if (meta.urn) aliases.push(meta.urn);
|
|
117
|
+
// Common fallbacks for known short names
|
|
118
|
+
if (res === 'webagents') aliases.push('urn:sap:destination:WEBAGENTS_BACKEND', 'urn:sap:destination:web_agents_gateway');
|
|
119
|
+
if (res === 'a2a') aliases.push('urn:sap:identity:application:provider:name:agent-gateway');
|
|
116
120
|
}
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
// No resource = try first entry
|
|
122
|
+
if (!res) {
|
|
123
|
+
const first = [...resourcesMap.values()][0];
|
|
124
|
+
if (!first) return null;
|
|
125
|
+
const map = deviceDoc.getMap(first);
|
|
126
|
+
const expiresAt = map.get('expires_at');
|
|
127
|
+
if (expiresAt && expiresAt < Date.now()) return null;
|
|
128
|
+
if (!map.get('ciphertext')) return null;
|
|
129
|
+
return map;
|
|
130
|
+
}
|
|
131
|
+
for (const alias of aliases) {
|
|
132
|
+
const key = resourcesMap.get(alias);
|
|
133
|
+
if (!key) continue;
|
|
134
|
+
const map = deviceDoc.getMap(key);
|
|
135
|
+
const expiresAt = map.get('expires_at');
|
|
136
|
+
if (expiresAt && expiresAt < Date.now()) continue;
|
|
137
|
+
if (!map.get('ciphertext')) continue;
|
|
138
|
+
return map;
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
119
141
|
}
|
|
120
142
|
|
|
121
143
|
// ─── Output ───────────────────────────────────────────────────────────────────
|