@qoniai/qoni 0.5.1 → 0.5.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/CHANGELOG.md +8 -0
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/dist/index.cjs +79 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +79 -82
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1309,7 +1309,7 @@ declare class Qoni {
|
|
|
1309
1309
|
* while still giving literal autocomplete and letting you write an exhaustive
|
|
1310
1310
|
* `switch (err.code)` over the known set.
|
|
1311
1311
|
*/
|
|
1312
|
-
type QoniErrorCode = "qoni_error" | "auth.failed" | "delegation.required" | "permission_denied" | "token.expired" | "validation.failed" | "rate_limit.exceeded" | "upstream.failed" | "timeout" | "not_found" | "conflict" | "eak.delegation.user_not_bound" | "eak.genauth.userpool_binding_missing" | "eak.genauth.userpool_owner_missing" | "eak.genauth.no_bound_users" | "eak.token_exchange.upstream_failed" | (string & {});
|
|
1312
|
+
type QoniErrorCode = "qoni_error" | "auth.failed" | "delegation.required" | "permission_denied" | "token.expired" | "validation.failed" | "rate_limit.exceeded" | "upstream.failed" | "timeout" | "not_found" | "conflict" | "eak.delegation.user_not_bound" | "eak.delegation.no_allowed_scopes" | "eak.delegation.scope_not_allowed" | "eak.genauth.userpool_binding_missing" | "eak.genauth.userpool_owner_missing" | "eak.genauth.no_bound_users" | "eak.token_exchange.upstream_failed" | (string & {});
|
|
1313
1313
|
interface QoniErrorOptions {
|
|
1314
1314
|
code?: QoniErrorCode;
|
|
1315
1315
|
status?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1309,7 +1309,7 @@ declare class Qoni {
|
|
|
1309
1309
|
* while still giving literal autocomplete and letting you write an exhaustive
|
|
1310
1310
|
* `switch (err.code)` over the known set.
|
|
1311
1311
|
*/
|
|
1312
|
-
type QoniErrorCode = "qoni_error" | "auth.failed" | "delegation.required" | "permission_denied" | "token.expired" | "validation.failed" | "rate_limit.exceeded" | "upstream.failed" | "timeout" | "not_found" | "conflict" | "eak.delegation.user_not_bound" | "eak.genauth.userpool_binding_missing" | "eak.genauth.userpool_owner_missing" | "eak.genauth.no_bound_users" | "eak.token_exchange.upstream_failed" | (string & {});
|
|
1312
|
+
type QoniErrorCode = "qoni_error" | "auth.failed" | "delegation.required" | "permission_denied" | "token.expired" | "validation.failed" | "rate_limit.exceeded" | "upstream.failed" | "timeout" | "not_found" | "conflict" | "eak.delegation.user_not_bound" | "eak.delegation.no_allowed_scopes" | "eak.delegation.scope_not_allowed" | "eak.genauth.userpool_binding_missing" | "eak.genauth.userpool_owner_missing" | "eak.genauth.no_bound_users" | "eak.token_exchange.upstream_failed" | (string & {});
|
|
1313
1313
|
interface QoniErrorOptions {
|
|
1314
1314
|
code?: QoniErrorCode;
|
|
1315
1315
|
status?: number;
|
package/dist/index.js
CHANGED
|
@@ -56,81 +56,6 @@ function buildSignedHeaders(credentials, method, pathname, payload) {
|
|
|
56
56
|
return headers;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// src/scopes.ts
|
|
60
|
-
var QoniScopes = {
|
|
61
|
-
GUMEM_SESSION_CREATE: "gumem.session:create",
|
|
62
|
-
GUMEM_MESSAGE_WRITE: "gumem.message:write",
|
|
63
|
-
GUMEM_MEMORY_READ: "gumem.memory:read",
|
|
64
|
-
GUMEM_MEMORY_WRITE: "gumem.memory:write",
|
|
65
|
-
GUMEM_MEMORY_DELETE: "gumem.memory:delete",
|
|
66
|
-
GUMEM_SEARCH_RUN: "gumem.search:run",
|
|
67
|
-
GUMEM_ADMIN_MANAGE: "gumem.admin:manage",
|
|
68
|
-
GUMEM_RESOURCE_WRITE: "gumem.resource:write",
|
|
69
|
-
GUMEM_ACTION_WRITE: "gumem.action:write",
|
|
70
|
-
GUMEM_ACTION_READ: "gumem.action:read",
|
|
71
|
-
GUMEM_PROFILE_READ: "gumem.profile:read",
|
|
72
|
-
// WebAgent products: exactly two verbs per product — `read` (observe) and
|
|
73
|
-
// `manage` (anything that changes execution state). See
|
|
74
|
-
// wa/docs/qoni-sdk-public-surface.md §3.
|
|
75
|
-
DO_ANYTHING_READ: "webagent.do_anything:read",
|
|
76
|
-
DO_ANYTHING_MANAGE: "webagent.do_anything:manage",
|
|
77
|
-
WEB_SEARCH_READ: "webagent.web_search:read",
|
|
78
|
-
WEB_SEARCH_MANAGE: "webagent.web_search:manage",
|
|
79
|
-
DEEP_RESEARCH_READ: "webagent.deep_research:read",
|
|
80
|
-
DEEP_RESEARCH_MANAGE: "webagent.deep_research:manage",
|
|
81
|
-
TRACK_READ: "webagent.track:read",
|
|
82
|
-
TRACK_MANAGE: "webagent.track:manage"
|
|
83
|
-
};
|
|
84
|
-
var QoniProductScopes = {
|
|
85
|
-
doAnything: [
|
|
86
|
-
QoniScopes.DO_ANYTHING_READ,
|
|
87
|
-
QoniScopes.DO_ANYTHING_MANAGE
|
|
88
|
-
],
|
|
89
|
-
webSearch: [
|
|
90
|
-
QoniScopes.WEB_SEARCH_READ,
|
|
91
|
-
QoniScopes.WEB_SEARCH_MANAGE
|
|
92
|
-
],
|
|
93
|
-
deepResearch: [
|
|
94
|
-
QoniScopes.DEEP_RESEARCH_READ,
|
|
95
|
-
QoniScopes.DEEP_RESEARCH_MANAGE
|
|
96
|
-
],
|
|
97
|
-
track: [
|
|
98
|
-
QoniScopes.TRACK_READ,
|
|
99
|
-
QoniScopes.TRACK_MANAGE
|
|
100
|
-
]
|
|
101
|
-
};
|
|
102
|
-
var KNOWN_SCOPES = Object.values(QoniScopes);
|
|
103
|
-
var QoniScopeBundles = {
|
|
104
|
-
GUMEM_READONLY: [QoniScopes.GUMEM_MEMORY_READ, QoniScopes.GUMEM_PROFILE_READ],
|
|
105
|
-
GUMEM_SESSION_RECALL: [
|
|
106
|
-
QoniScopes.GUMEM_MEMORY_READ,
|
|
107
|
-
QoniScopes.GUMEM_MEMORY_WRITE,
|
|
108
|
-
QoniScopes.GUMEM_MESSAGE_WRITE
|
|
109
|
-
],
|
|
110
|
-
GUMEM_WRITE: [
|
|
111
|
-
QoniScopes.GUMEM_SESSION_CREATE,
|
|
112
|
-
QoniScopes.GUMEM_MESSAGE_WRITE,
|
|
113
|
-
QoniScopes.GUMEM_ACTION_WRITE
|
|
114
|
-
],
|
|
115
|
-
// One bundle per WebAgent product = [read, manage].
|
|
116
|
-
DO_ANYTHING: [
|
|
117
|
-
QoniScopes.DO_ANYTHING_READ,
|
|
118
|
-
QoniScopes.DO_ANYTHING_MANAGE
|
|
119
|
-
],
|
|
120
|
-
WEB_SEARCH: [
|
|
121
|
-
QoniScopes.WEB_SEARCH_READ,
|
|
122
|
-
QoniScopes.WEB_SEARCH_MANAGE
|
|
123
|
-
],
|
|
124
|
-
DEEP_RESEARCH: [
|
|
125
|
-
QoniScopes.DEEP_RESEARCH_READ,
|
|
126
|
-
QoniScopes.DEEP_RESEARCH_MANAGE
|
|
127
|
-
],
|
|
128
|
-
TRACK: [
|
|
129
|
-
QoniScopes.TRACK_READ,
|
|
130
|
-
QoniScopes.TRACK_MANAGE
|
|
131
|
-
]
|
|
132
|
-
};
|
|
133
|
-
|
|
134
59
|
// src/types.ts
|
|
135
60
|
function isJsonObject(value) {
|
|
136
61
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -214,7 +139,7 @@ function errorFromPayload(status, payload, fallbackMessage) {
|
|
|
214
139
|
const source = detailObject || (isJsonObject(payload) ? payload : {});
|
|
215
140
|
const code = stringField(source, "code") || stringField(source, "apiCode") || statusCodeToCode(status);
|
|
216
141
|
const rawMessage = stringField(source, "message") || stringField(source, "detail") || fallbackMessage;
|
|
217
|
-
const message = appendOnboardingHint(
|
|
142
|
+
const message = code === "eak.delegation.no_allowed_scopes" ? "This AccessKey has no permission scopes. In Qoni Console, open its Permission scope settings, enable the policy needed for this call, then retry." : appendOnboardingHint(
|
|
218
143
|
appendDeniedScopes(appendUpstreamDescription(rawMessage, source), source),
|
|
219
144
|
code
|
|
220
145
|
);
|
|
@@ -231,7 +156,7 @@ function errorFromPayload(status, payload, fallbackMessage) {
|
|
|
231
156
|
if (isDelegationRequired(code)) return new QoniDelegationRequiredError(message, options);
|
|
232
157
|
if (status === 401) return new QoniAuthError(message, options);
|
|
233
158
|
if (status === 403 || isPermissionDenied(code)) {
|
|
234
|
-
return new QoniPermissionDeniedError(
|
|
159
|
+
return new QoniPermissionDeniedError(message, options);
|
|
235
160
|
}
|
|
236
161
|
if (status === 400 || status === 422) return new QoniValidationError(message, options);
|
|
237
162
|
if (status === 429) return new QoniRateLimitError(message, options);
|
|
@@ -266,17 +191,14 @@ function appendUpstreamDescription(message, source) {
|
|
|
266
191
|
}
|
|
267
192
|
var ONBOARDING_HINTS = {
|
|
268
193
|
"eak.delegation.user_not_bound": "Hint: the userId is not in the GenAuth userpool bound to this credential. Resolve a real user with qoni.resolveAnyBoundUser() (demo/smoke) or qoni.currentUser({ accessToken }).",
|
|
269
|
-
"eak.genauth.userpool_binding_missing": "Hint: bind the Qoni credential to a GenAuth userpool before calling genauth.users.*."
|
|
194
|
+
"eak.genauth.userpool_binding_missing": "Hint: bind the Qoni credential to a GenAuth userpool before calling genauth.users.*.",
|
|
195
|
+
"eak.delegation.scope_not_allowed": "Hint: enable the denied scopes in this AccessKey's Permission scope settings in Qoni Console."
|
|
270
196
|
};
|
|
271
197
|
function appendOnboardingHint(message, code) {
|
|
272
198
|
const hint = ONBOARDING_HINTS[code];
|
|
273
199
|
if (!hint || message.includes(hint)) return message;
|
|
274
200
|
return `${message} ${hint}`;
|
|
275
201
|
}
|
|
276
|
-
function appendKnownScopes(message) {
|
|
277
|
-
if (message.includes("Known scopes:")) return message;
|
|
278
|
-
return `${message} (Known scopes: ${KNOWN_SCOPES.join(", ")})`;
|
|
279
|
-
}
|
|
280
202
|
function statusCodeToCode(status) {
|
|
281
203
|
if (status === 401) return "auth.failed";
|
|
282
204
|
if (status === 403) return "permission_denied";
|
|
@@ -1440,6 +1362,81 @@ function createQoniNamespace(_transport, delegateToken, completeDelegateToken) {
|
|
|
1440
1362
|
};
|
|
1441
1363
|
}
|
|
1442
1364
|
|
|
1365
|
+
// src/scopes.ts
|
|
1366
|
+
var QoniScopes = {
|
|
1367
|
+
GUMEM_SESSION_CREATE: "gumem.session:create",
|
|
1368
|
+
GUMEM_MESSAGE_WRITE: "gumem.message:write",
|
|
1369
|
+
GUMEM_MEMORY_READ: "gumem.memory:read",
|
|
1370
|
+
GUMEM_MEMORY_WRITE: "gumem.memory:write",
|
|
1371
|
+
GUMEM_MEMORY_DELETE: "gumem.memory:delete",
|
|
1372
|
+
GUMEM_SEARCH_RUN: "gumem.search:run",
|
|
1373
|
+
GUMEM_ADMIN_MANAGE: "gumem.admin:manage",
|
|
1374
|
+
GUMEM_RESOURCE_WRITE: "gumem.resource:write",
|
|
1375
|
+
GUMEM_ACTION_WRITE: "gumem.action:write",
|
|
1376
|
+
GUMEM_ACTION_READ: "gumem.action:read",
|
|
1377
|
+
GUMEM_PROFILE_READ: "gumem.profile:read",
|
|
1378
|
+
// WebAgent products: exactly two verbs per product — `read` (observe) and
|
|
1379
|
+
// `manage` (anything that changes execution state). See
|
|
1380
|
+
// wa/docs/qoni-sdk-public-surface.md §3.
|
|
1381
|
+
DO_ANYTHING_READ: "webagent.do_anything:read",
|
|
1382
|
+
DO_ANYTHING_MANAGE: "webagent.do_anything:manage",
|
|
1383
|
+
WEB_SEARCH_READ: "webagent.web_search:read",
|
|
1384
|
+
WEB_SEARCH_MANAGE: "webagent.web_search:manage",
|
|
1385
|
+
DEEP_RESEARCH_READ: "webagent.deep_research:read",
|
|
1386
|
+
DEEP_RESEARCH_MANAGE: "webagent.deep_research:manage",
|
|
1387
|
+
TRACK_READ: "webagent.track:read",
|
|
1388
|
+
TRACK_MANAGE: "webagent.track:manage"
|
|
1389
|
+
};
|
|
1390
|
+
var QoniProductScopes = {
|
|
1391
|
+
doAnything: [
|
|
1392
|
+
QoniScopes.DO_ANYTHING_READ,
|
|
1393
|
+
QoniScopes.DO_ANYTHING_MANAGE
|
|
1394
|
+
],
|
|
1395
|
+
webSearch: [
|
|
1396
|
+
QoniScopes.WEB_SEARCH_READ,
|
|
1397
|
+
QoniScopes.WEB_SEARCH_MANAGE
|
|
1398
|
+
],
|
|
1399
|
+
deepResearch: [
|
|
1400
|
+
QoniScopes.DEEP_RESEARCH_READ,
|
|
1401
|
+
QoniScopes.DEEP_RESEARCH_MANAGE
|
|
1402
|
+
],
|
|
1403
|
+
track: [
|
|
1404
|
+
QoniScopes.TRACK_READ,
|
|
1405
|
+
QoniScopes.TRACK_MANAGE
|
|
1406
|
+
]
|
|
1407
|
+
};
|
|
1408
|
+
var KNOWN_SCOPES = Object.values(QoniScopes);
|
|
1409
|
+
var QoniScopeBundles = {
|
|
1410
|
+
GUMEM_READONLY: [QoniScopes.GUMEM_MEMORY_READ, QoniScopes.GUMEM_PROFILE_READ],
|
|
1411
|
+
GUMEM_SESSION_RECALL: [
|
|
1412
|
+
QoniScopes.GUMEM_MEMORY_READ,
|
|
1413
|
+
QoniScopes.GUMEM_MEMORY_WRITE,
|
|
1414
|
+
QoniScopes.GUMEM_MESSAGE_WRITE
|
|
1415
|
+
],
|
|
1416
|
+
GUMEM_WRITE: [
|
|
1417
|
+
QoniScopes.GUMEM_SESSION_CREATE,
|
|
1418
|
+
QoniScopes.GUMEM_MESSAGE_WRITE,
|
|
1419
|
+
QoniScopes.GUMEM_ACTION_WRITE
|
|
1420
|
+
],
|
|
1421
|
+
// One bundle per WebAgent product = [read, manage].
|
|
1422
|
+
DO_ANYTHING: [
|
|
1423
|
+
QoniScopes.DO_ANYTHING_READ,
|
|
1424
|
+
QoniScopes.DO_ANYTHING_MANAGE
|
|
1425
|
+
],
|
|
1426
|
+
WEB_SEARCH: [
|
|
1427
|
+
QoniScopes.WEB_SEARCH_READ,
|
|
1428
|
+
QoniScopes.WEB_SEARCH_MANAGE
|
|
1429
|
+
],
|
|
1430
|
+
DEEP_RESEARCH: [
|
|
1431
|
+
QoniScopes.DEEP_RESEARCH_READ,
|
|
1432
|
+
QoniScopes.DEEP_RESEARCH_MANAGE
|
|
1433
|
+
],
|
|
1434
|
+
TRACK: [
|
|
1435
|
+
QoniScopes.TRACK_READ,
|
|
1436
|
+
QoniScopes.TRACK_MANAGE
|
|
1437
|
+
]
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1443
1440
|
// src/genauth.ts
|
|
1444
1441
|
function createGenAuthNamespace(transport, options = {}) {
|
|
1445
1442
|
return {
|