@experiture/xyra-cli 0.6.1 → 0.6.4

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.
@@ -35,10 +35,18 @@ var require_xyra_administration = __commonJS({
35
35
  "../../libs/xyra-types/dist/xyra-administration.js"(exports2) {
36
36
  "use strict";
37
37
  Object.defineProperty(exports2, "__esModule", { value: true });
38
+ exports2.runtimeAdministrationTarget = runtimeAdministrationTarget;
38
39
  exports2.parseXyraAdministrationTargetV1 = parseXyraAdministrationTargetV12;
39
40
  exports2.xyraAdministrationTargetKeyV1 = xyraAdministrationTargetKeyV1;
40
41
  exports2.parseXyraAdministrationResolvedTargetV1 = parseXyraAdministrationResolvedTargetV1;
41
42
  exports2.parseXyraAdministrationDecisionV1 = parseXyraAdministrationDecisionV1;
43
+ function runtimeAdministrationTarget(identity) {
44
+ return identity.licenseSourceProductId !== identity.licensedProductId && identity.tenantId === identity.licenseOwnerTenantId ? {
45
+ targetKind: "configuration-owner",
46
+ configurationTenantId: identity.licenseOwnerTenantId,
47
+ managedProductId: identity.licenseSourceProductId
48
+ } : { targetKind: "customer-resource", targetTenantId: identity.tenantId, activeProductId: identity.productId };
49
+ }
42
50
  var identifier = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,49}$/.test(value);
43
51
  var guid = (value) => typeof value === "string" && /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(value) && value !== "00000000-0000-0000-0000-000000000000";
44
52
  var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
@@ -76,7 +84,7 @@ var require_xyra_administration = __commonJS({
76
84
  const base = ["targetKind", "managedProductId", "relationshipKind", "activeProductId", "actualTenantId", "licensedProductId", "commercialState"];
77
85
  const embedded = ["licenseSourceProductId", "licenseOwnerTenantId", "bindingId", "entitlementId", "sourceEntitlementId"];
78
86
  const isNative = value.relationshipKind === "native-product-tenant";
79
- if (!isNative && value.relationshipKind !== "embedded-product-entitlement" || !exact(value, isNative ? base : [...base, ...embedded]) || value.licensedProductId !== "xyra-ai" || !base.filter((key) => !["targetKind", "relationshipKind"].includes(key)).every((key) => identifier(value[key])) || (isNative ? value.activeProductId !== "xyra-ai" : !embedded.every((key) => identifier(value[key]))) || value.actualTenantId !== (target.targetKind === "customer-resource" ? target.targetTenantId : target.configurationTenantId) || target.targetKind === "customer-resource" && value.activeProductId !== target.activeProductId || target.targetKind === "configuration-owner" && value.activeProductId !== target.managedProductId || !isNative && (value.licenseSourceProductId !== value.activeProductId || !["bindingId", "entitlementId", "sourceEntitlementId"].every((key) => guid(value[key])) || target.targetKind === "configuration-owner" && value.licenseOwnerTenantId !== target.configurationTenantId))
87
+ if (!isNative && value.relationshipKind !== "embedded-product-entitlement" || !exact(value, isNative ? base : [...base, ...embedded]) || value.licensedProductId !== "xyra-ai" || !base.filter((key) => !["targetKind", "relationshipKind"].includes(key)).every((key) => identifier(value[key])) || (isNative ? value.activeProductId !== "xyra-ai" : !embedded.every((key) => identifier(value[key]))) || value.actualTenantId !== (target.targetKind === "customer-resource" ? target.targetTenantId : target.configurationTenantId) || target.targetKind === "customer-resource" && value.activeProductId !== target.activeProductId || target.targetKind === "configuration-owner" && value.activeProductId !== target.managedProductId || !isNative && (value.activeProductId !== value.licenseSourceProductId && value.activeProductId !== value.licensedProductId || !["bindingId", "entitlementId", "sourceEntitlementId"].every((key) => guid(value[key])) || target.targetKind === "configuration-owner" && (value.licenseOwnerTenantId !== target.configurationTenantId || value.licenseSourceProductId !== target.managedProductId)))
80
88
  return null;
81
89
  return { ...value };
82
90
  }
@@ -92,17 +100,23 @@ var require_xyra_administration = __commonJS({
92
100
  "targetTenantId",
93
101
  "grantId",
94
102
  "target",
95
- "resolvedTarget"
96
- ]) || value.operationId !== request.operationId || value.purpose !== purpose || value.accessPurpose !== "administration" || value.productId !== "xyra-ai" || typeof value.allowed !== "boolean" || typeof value.code !== "string" || !/^[A-Z0-9_.]{1,160}$/.test(value.code) || !(value.operatorTenantId === null || identifier(value.operatorTenantId)) || !(value.grantId === null || guid(value.grantId)))
103
+ "resolvedTarget",
104
+ ...Object.prototype.hasOwnProperty.call(value, "configurationAccess") ? ["configurationAccess"] : []
105
+ ]) || value.configurationAccess !== void 0 && !["read", "manage", "manage_selection"].includes(String(value.configurationAccess)) || value.operationId !== request.operationId || value.purpose !== purpose || value.accessPurpose !== "administration" || value.productId !== "xyra-ai" || typeof value.allowed !== "boolean" || typeof value.code !== "string" || !/^[A-Z0-9_.]{1,160}$/.test(value.code) || !(value.operatorTenantId === null || identifier(value.operatorTenantId)) || !(value.grantId === null || guid(value.grantId)))
97
106
  return null;
98
107
  const target = parseXyraAdministrationTargetV12(value.target);
99
108
  if (!target || xyraAdministrationTargetKeyV1(target) !== xyraAdministrationTargetKeyV1(request.target) || value.targetTenantId !== (target.targetKind === "global-resource" ? null : target.targetKind === "configuration-owner" ? target.configurationTenantId : target.targetTenantId))
100
109
  return null;
101
110
  const resolvedTarget = parseXyraAdministrationResolvedTargetV1(value.resolvedTarget, target);
102
111
  if (value.allowed) {
103
- if (!resolvedTarget || (value.code === "AUTHORIZATION.ALLOWED.SUPER_USER" ? value.operatorTenantId !== null || value.grantId !== null : !["AUTHORIZATION.ALLOWED", "AUTHORIZATION.ALLOWED.LICENSEE"].includes(value.code) || value.operatorTenantId === null || value.grantId === null))
112
+ if (!resolvedTarget)
113
+ return null;
114
+ if (value.code === "AUTHORIZATION.ALLOWED.SAME_TENANT") {
115
+ if (target.targetKind !== "customer-resource" || value.operatorTenantId !== target.targetTenantId || value.grantId !== null)
116
+ return null;
117
+ } else if (value.code === "AUTHORIZATION.ALLOWED.SUPER_USER" ? value.operatorTenantId !== null || value.grantId !== null : !["AUTHORIZATION.ALLOWED", "AUTHORIZATION.ALLOWED.LICENSEE"].includes(value.code) || value.operatorTenantId === null || value.grantId === null)
104
118
  return null;
105
- if (value.code === "AUTHORIZATION.ALLOWED.LICENSEE" && (target.targetKind === "global-resource" || resolvedTarget.relationshipKind !== "embedded-product-entitlement" || resolvedTarget.licenseOwnerTenantId !== value.operatorTenantId || resolvedTarget.activeProductId === "xyra-ai"))
119
+ if (value.code === "AUTHORIZATION.ALLOWED.LICENSEE" && (target.targetKind === "global-resource" || resolvedTarget.relationshipKind !== "embedded-product-entitlement" || resolvedTarget.licenseOwnerTenantId !== value.operatorTenantId))
106
120
  return null;
107
121
  } else if (value.code.startsWith("AUTHORIZATION.ALLOWED") || value.resolvedTarget !== null)
108
122
  return null;
@@ -116,13 +130,15 @@ var require_canonical_runtime_json = __commonJS({
116
130
  "../../libs/xyra-types/dist/canonical-runtime-json.js"(exports2) {
117
131
  "use strict";
118
132
  Object.defineProperty(exports2, "__esModule", { value: true });
119
- exports2.MAXIMUM_BOUNDED_RUNTIME_JSON_BYTES_V1 = exports2.BoundedRuntimeJsonErrorV1 = exports2.CanonicalRuntimeJsonErrorV1 = void 0;
133
+ exports2.MAXIMUM_EVALUATION_EVIDENCE_JSON_BYTES_V1 = exports2.MAXIMUM_BOUNDED_RUNTIME_JSON_BYTES_V1 = exports2.BoundedRuntimeJsonErrorV1 = exports2.CanonicalRuntimeJsonErrorV1 = void 0;
120
134
  exports2.canonicalRuntimeJsonV1 = canonicalRuntimeJsonV1;
121
135
  exports2.canonicalRuntimeUtf8BytesV1 = canonicalRuntimeUtf8BytesV1;
122
136
  exports2.canonicalRuntimeUtf8ByteLengthV1 = canonicalRuntimeUtf8ByteLengthV1;
123
137
  exports2.boundedRuntimeDataV1 = boundedRuntimeDataV1;
124
138
  exports2.boundedRuntimeJsonDataV1 = boundedRuntimeJsonDataV1;
139
+ exports2.boundedEvaluationEvidenceJsonDataV1 = boundedEvaluationEvidenceJsonDataV1;
125
140
  exports2.parseBoundedRuntimeJsonV1 = parseBoundedRuntimeJsonV12;
141
+ exports2.parseBoundedEvaluationEvidenceJsonV1 = parseBoundedEvaluationEvidenceJsonV1;
126
142
  var CanonicalRuntimeJsonErrorV1 = class extends TypeError {
127
143
  constructor(reason, path) {
128
144
  super(`Canonical runtime JSON rejected ${reason} at ${path}.`);
@@ -224,22 +240,25 @@ var require_canonical_runtime_json = __commonJS({
224
240
  return canonicalRuntimeUtf8BytesV1(value).byteLength;
225
241
  }
226
242
  var BoundedRuntimeJsonErrorV1 = class extends SyntaxError {
227
- constructor(reason) {
243
+ constructor(reason, rule = "syntax", at = []) {
228
244
  super(`Bounded runtime JSON rejected ${reason}.`);
229
245
  this.reason = reason;
246
+ this.rule = rule;
247
+ this.at = at;
230
248
  this.name = "BoundedRuntimeJsonErrorV1";
231
249
  }
232
250
  };
233
251
  exports2.BoundedRuntimeJsonErrorV1 = BoundedRuntimeJsonErrorV1;
234
- var boundedInvalid = (reason) => {
235
- throw new BoundedRuntimeJsonErrorV1(reason);
252
+ var boundedInvalid = (reason, rule, at = []) => {
253
+ throw new BoundedRuntimeJsonErrorV1(reason, rule, [...at]);
236
254
  };
237
255
  exports2.MAXIMUM_BOUNDED_RUNTIME_JSON_BYTES_V1 = 2097152;
238
- function boundedLimits(limits) {
256
+ exports2.MAXIMUM_EVALUATION_EVIDENCE_JSON_BYTES_V1 = 8388608;
257
+ function boundedLimits(limits, ceiling = exports2.MAXIMUM_BOUNDED_RUNTIME_JSON_BYTES_V1) {
239
258
  const maximumBytes = limits.maximumBytes ?? 1048576;
240
259
  const maximumDepth = limits.maximumDepth ?? 16;
241
- if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 1 || maximumBytes > exports2.MAXIMUM_BOUNDED_RUNTIME_JSON_BYTES_V1 || !Number.isSafeInteger(maximumDepth) || maximumDepth < 1 || maximumDepth > 24)
242
- boundedInvalid("limits");
260
+ if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 1 || maximumBytes > ceiling || !Number.isSafeInteger(maximumDepth) || maximumDepth < 1 || maximumDepth > 24)
261
+ boundedInvalid("limits", "limits");
243
262
  return { maximumBytes, maximumDepth };
244
263
  }
245
264
  function boundedUnicode(value) {
@@ -258,32 +277,39 @@ var require_canonical_runtime_json = __commonJS({
258
277
  let nodes = 0;
259
278
  let characters = 0;
260
279
  const ancestors = /* @__PURE__ */ new Set();
280
+ const at = [];
261
281
  function copy(value, depth) {
262
- if (++nodes > (jsonOnly ? 2e5 : 1e5) || depth > maximumDepth)
263
- boundedInvalid("shape");
282
+ if (++nodes > (jsonOnly ? 2e5 : 1e5))
283
+ boundedInvalid("shape", "nodes", at);
284
+ if (depth > maximumDepth)
285
+ boundedInvalid("shape", "depth", at);
264
286
  if (value === null || typeof value === "boolean" || !jsonOnly && value === void 0)
265
287
  return value;
266
288
  if (typeof value === "number" && Number.isFinite(value))
267
289
  return value;
268
290
  if (typeof value === "string") {
269
291
  characters += value.length;
270
- if (jsonOnly ? characters > maximumBytes || !boundedUnicode(value) : value.length > 1048576 || characters > 16777216)
271
- boundedInvalid("text");
292
+ if (jsonOnly ? characters > maximumBytes : value.length > 1048576 || characters > 16777216)
293
+ boundedInvalid("text", "bytes", at);
294
+ if (jsonOnly && !boundedUnicode(value))
295
+ boundedInvalid("text", "unicode", at);
272
296
  return value;
273
297
  }
274
298
  if (!value || typeof value !== "object" || ancestors.has(value))
275
- boundedInvalid("shape");
299
+ boundedInvalid("shape", "value_kind", at);
276
300
  const objectValue = value;
277
301
  const array = Array.isArray(objectValue);
278
302
  const prototype = Object.getPrototypeOf(objectValue);
279
303
  const arrayLength = array ? objectValue.length : 0;
280
304
  if (array ? prototype !== Array.prototype && (jsonOnly || prototype !== null) : prototype !== Object.prototype && prototype !== null)
281
- boundedInvalid("shape");
305
+ boundedInvalid("shape", "value_kind", at);
282
306
  const keys = Reflect.ownKeys(objectValue);
283
- if (keys.length > 10001 || keys.some((key) => typeof key !== "string"))
284
- boundedInvalid("shape");
307
+ if (keys.length > 10001)
308
+ boundedInvalid("shape", array ? "array_length" : "key_count", at);
309
+ if (keys.some((key) => typeof key !== "string"))
310
+ boundedInvalid("shape", "value_kind", at);
285
311
  if (array && keys.length !== arrayLength + 1)
286
- boundedInvalid("array");
312
+ boundedInvalid("array", "value_kind", at);
287
313
  const seen = /* @__PURE__ */ new Set();
288
314
  const result = array ? [] : {};
289
315
  ancestors.add(objectValue);
@@ -292,10 +318,18 @@ var require_canonical_runtime_json = __commonJS({
292
318
  if (array && key === "length")
293
319
  continue;
294
320
  const descriptor = Object.getOwnPropertyDescriptor(objectValue, key);
295
- if (!descriptor.enumerable || !("value" in descriptor) || key.length > (jsonOnly ? 160 : 256) || jsonOnly && seen.has(key.toLowerCase()) || array && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= arrayLength))
296
- boundedInvalid("shape");
297
- seen.add(key.toLowerCase());
321
+ if (!descriptor.enumerable || !("value" in descriptor))
322
+ boundedInvalid("shape", "value_kind", at);
323
+ if (key.length > (jsonOnly ? 160 : 256))
324
+ boundedInvalid("shape", "key_length", at);
325
+ if (jsonOnly && seen.has(key))
326
+ boundedInvalid("shape", "duplicate_key", at);
327
+ if (array && (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= arrayLength))
328
+ boundedInvalid("shape", "value_kind", at);
329
+ seen.add(key);
330
+ at.push(array ? Number(key) : key);
298
331
  Object.defineProperty(result, key, { enumerable: true, writable: true, configurable: true, value: copy(descriptor.value, depth + 1) });
332
+ at.pop();
299
333
  }
300
334
  } finally {
301
335
  ancestors.delete(objectValue);
@@ -308,18 +342,35 @@ var require_canonical_runtime_json = __commonJS({
308
342
  return copyBoundedRuntimeData(input, 16777216, 24, false, preserveKeyOrder);
309
343
  }
310
344
  function boundedRuntimeJsonDataV1(input, limits = {}) {
311
- const { maximumBytes, maximumDepth } = boundedLimits(limits);
345
+ return copyBoundedJsonData(input, boundedLimits(limits));
346
+ }
347
+ function boundedEvaluationEvidenceJsonDataV1(input, limits = {}) {
348
+ return copyBoundedJsonData(input, boundedLimits(limits, exports2.MAXIMUM_EVALUATION_EVIDENCE_JSON_BYTES_V1));
349
+ }
350
+ function copyBoundedJsonData(input, { maximumBytes, maximumDepth }) {
312
351
  const value = copyBoundedRuntimeData(input, maximumBytes, maximumDepth, true);
313
352
  if (canonicalRuntimeUtf8ByteLengthV1(value) > maximumBytes)
314
- boundedInvalid("bytes");
353
+ boundedInvalid("bytes", "bytes");
315
354
  return value;
316
355
  }
317
356
  function parseBoundedRuntimeJsonV12(source, limits = {}) {
318
- const { maximumBytes, maximumDepth } = boundedLimits(limits);
319
- if (typeof source !== "string" || source.length > maximumBytes || !boundedUnicode(source) || new TextEncoder().encode(source).byteLength > maximumBytes)
320
- boundedInvalid("bytes");
357
+ return parseBoundedJson(source, boundedLimits(limits));
358
+ }
359
+ function parseBoundedEvaluationEvidenceJsonV1(source, limits = {}) {
360
+ return parseBoundedJson(source, boundedLimits(limits, exports2.MAXIMUM_EVALUATION_EVIDENCE_JSON_BYTES_V1));
361
+ }
362
+ function parseBoundedJson(source, { maximumBytes, maximumDepth }) {
363
+ if (typeof source !== "string")
364
+ boundedInvalid("bytes", "value_kind");
365
+ if (source.length > maximumBytes)
366
+ boundedInvalid("bytes", "bytes");
367
+ if (!boundedUnicode(source))
368
+ boundedInvalid("bytes", "unicode");
369
+ if (new TextEncoder().encode(source).byteLength > maximumBytes)
370
+ boundedInvalid("bytes", "bytes");
321
371
  let index = 0;
322
372
  let nodes = 0;
373
+ const at = [];
323
374
  const whitespace = () => {
324
375
  while (/[\x20\t\r\n]/.test(source[index] ?? "\0"))
325
376
  index += 1;
@@ -327,7 +378,7 @@ var require_canonical_runtime_json = __commonJS({
327
378
  function string() {
328
379
  const start = index;
329
380
  if (source[index++] !== '"')
330
- boundedInvalid("string");
381
+ boundedInvalid("string", "syntax", at);
331
382
  while (index < source.length) {
332
383
  const char = source[index++];
333
384
  if (char === "\\") {
@@ -338,20 +389,22 @@ var require_canonical_runtime_json = __commonJS({
338
389
  try {
339
390
  const parsed = JSON.parse(source.slice(start, index));
340
391
  if (!boundedUnicode(parsed))
341
- boundedInvalid("unicode");
392
+ boundedInvalid("unicode", "unicode", at);
342
393
  return parsed;
343
394
  } catch (error) {
344
395
  if (error instanceof BoundedRuntimeJsonErrorV1)
345
396
  throw error;
346
- boundedInvalid("string");
397
+ boundedInvalid("string", "syntax", at);
347
398
  }
348
399
  }
349
400
  }
350
- return boundedInvalid("string");
401
+ return boundedInvalid("string", "syntax", at);
351
402
  }
352
403
  function value(depth) {
353
- if (++nodes > 2e5 || depth > maximumDepth)
354
- boundedInvalid("shape");
404
+ if (++nodes > 2e5)
405
+ boundedInvalid("shape", "nodes", at);
406
+ if (depth > maximumDepth)
407
+ boundedInvalid("shape", "depth", at);
355
408
  whitespace();
356
409
  const char = source[index];
357
410
  if (char === '"') {
@@ -367,20 +420,22 @@ var require_canonical_runtime_json = __commonJS({
367
420
  return;
368
421
  }
369
422
  for (; ; ) {
370
- const item = string().toLowerCase();
371
- if (seen.has(item))
372
- boundedInvalid("duplicate_key");
373
- seen.add(item);
423
+ const key = string();
424
+ if (seen.has(key))
425
+ boundedInvalid("duplicate_key", "duplicate_key", at);
426
+ seen.add(key);
374
427
  whitespace();
375
428
  if (source[index++] !== ":")
376
- boundedInvalid("object");
429
+ boundedInvalid("object", "syntax", at);
430
+ at.push(key);
377
431
  value(depth + 1);
432
+ at.pop();
378
433
  whitespace();
379
434
  const end = source[index++];
380
435
  if (end === "}")
381
436
  return;
382
437
  if (end !== ",")
383
- boundedInvalid("object");
438
+ boundedInvalid("object", "syntax", at);
384
439
  whitespace();
385
440
  }
386
441
  }
@@ -394,28 +449,30 @@ var require_canonical_runtime_json = __commonJS({
394
449
  let count = 0;
395
450
  for (; ; ) {
396
451
  if (++count > 1e4)
397
- boundedInvalid("array");
452
+ boundedInvalid("array", "array_length", at);
453
+ at.push(count - 1);
398
454
  value(depth + 1);
455
+ at.pop();
399
456
  whitespace();
400
457
  const end = source[index++];
401
458
  if (end === "]")
402
459
  return;
403
460
  if (end !== ",")
404
- boundedInvalid("array");
461
+ boundedInvalid("array", "syntax", at);
405
462
  whitespace();
406
463
  }
407
464
  }
408
465
  const token = /^(?:true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)/.exec(source.slice(index));
409
466
  if (!token)
410
- boundedInvalid("value");
467
+ boundedInvalid("value", "syntax", at);
411
468
  const tokenText = token[0];
412
469
  if (/^-?\d/.test(tokenText)) {
413
470
  const numeric = Number(tokenText);
414
471
  if (!Number.isFinite(numeric))
415
- boundedInvalid("number");
472
+ boundedInvalid("number", "number", at);
416
473
  if (Number.isInteger(numeric)) {
417
474
  if (!Number.isSafeInteger(numeric))
418
- boundedInvalid("number");
475
+ boundedInvalid("number", "number", at);
419
476
  const parts = /^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/.exec(tokenText);
420
477
  let digits = (parts[2] + (parts[3] ?? "")).replace(/^0+/, "");
421
478
  let power = Number(parts[4] ?? 0) - (parts[3]?.length ?? 0);
@@ -424,7 +481,7 @@ var require_canonical_runtime_json = __commonJS({
424
481
  power += digits.length - trimmed.length;
425
482
  digits = trimmed;
426
483
  if (power < 0 || digits.length + power > 16 || Number(digits + "0".repeat(power)) !== Math.abs(numeric))
427
- boundedInvalid("number");
484
+ boundedInvalid("number", "number", at);
428
485
  }
429
486
  }
430
487
  }
@@ -433,13 +490,13 @@ var require_canonical_runtime_json = __commonJS({
433
490
  value(0);
434
491
  whitespace();
435
492
  if (index !== source.length)
436
- boundedInvalid("trailing");
493
+ boundedInvalid("trailing", "syntax");
437
494
  try {
438
- return boundedRuntimeJsonDataV1(JSON.parse(source), limits);
495
+ return copyBoundedJsonData(JSON.parse(source), { maximumBytes, maximumDepth });
439
496
  } catch (error) {
440
497
  if (error instanceof BoundedRuntimeJsonErrorV1)
441
498
  throw error;
442
- return boundedInvalid("json");
499
+ return boundedInvalid("json", "syntax");
443
500
  }
444
501
  }
445
502
  }
@@ -455,38 +512,7 @@ module.exports = __toCommonJS(configStore_exports);
455
512
  var import_node_fs = require("node:fs");
456
513
  var import_node_os = require("node:os");
457
514
  var import_node_path = require("node:path");
458
-
459
- // src/errors/CliError.ts
460
- var CliError = class extends Error {
461
- code;
462
- hint;
463
- httpStatus;
464
- constructor(code, message, hint, httpStatus) {
465
- super(message);
466
- this.name = "CliError";
467
- this.code = code;
468
- this.hint = hint;
469
- this.httpStatus = httpStatus;
470
- }
471
- };
472
- var CliErrorCodes = {
473
- ConfigInvalid: "XYRA.CLI.CONFIG_INVALID",
474
- EnvironmentNotFound: "XYRA.CLI.ENVIRONMENT_NOT_FOUND",
475
- NotAuthenticated: "XYRA.CLI.NOT_AUTHENTICATED",
476
- OAuthStateMismatch: "XYRA.CLI.OAUTH_STATE_MISMATCH",
477
- OAuthCallbackError: "XYRA.CLI.OAUTH_CALLBACK_ERROR",
478
- TokenStoreUnavailable: "XYRA.CLI.TOKEN_STORE_UNAVAILABLE",
479
- TokenExchangeFailed: "XYRA.CLI.TOKEN_EXCHANGE_FAILED",
480
- InsufficientScope: "XYRA.CLI.INSUFFICIENT_SCOPE",
481
- McpProtocolError: "XYRA.CLI.MCP_PROTOCOL_ERROR",
482
- ToolCallFailed: "XYRA.CLI.TOOL_CALL_FAILED",
483
- ChatRequestFailed: "XYRA.CLI.CHAT_REQUEST_FAILED",
484
- InvalidArguments: "XYRA.CLI.INVALID_ARGUMENTS",
485
- ConfirmationRequired: "XYRA.CLI.CONFIRMATION_REQUIRED",
486
- AmbiguousAlias: "XYRA.CLI.AMBIGUOUS_ALIAS"
487
- };
488
-
489
- // src/config/configStore.ts
515
+ var import_CliError = require("../errors/CliError");
490
516
  var import_xyra_administration = __toESM(require_xyra_administration());
491
517
  var import_canonical_runtime_json = __toESM(require_canonical_runtime_json());
492
518
 
@@ -536,12 +562,12 @@ function requireHttpsOrTest(name, url) {
536
562
  try {
537
563
  parsed = new URL(url);
538
564
  } catch {
539
- throw new CliError(CliErrorCodes.ConfigInvalid, `Environment '${name}' has an invalid URL: ${url}`);
565
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Environment '${name}' has an invalid URL: ${url}`);
540
566
  }
541
567
  const isTestDomain = parsed.hostname.endsWith(".test");
542
568
  if (parsed.protocol !== "https:" && !isTestDomain) {
543
- throw new CliError(
544
- CliErrorCodes.ConfigInvalid,
569
+ throw new import_CliError.CliError(
570
+ import_CliError.CliErrorCodes.ConfigInvalid,
545
571
  `Environment '${name}' must use https (got ${parsed.protocol}//${parsed.host}).`
546
572
  );
547
573
  }
@@ -551,14 +577,14 @@ function requireHttpOrigin(name, url) {
551
577
  try {
552
578
  parsed = new URL(url);
553
579
  } catch {
554
- throw new CliError(CliErrorCodes.ConfigInvalid, `Environment '${name}' has an invalid URL: ${url}`);
580
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Environment '${name}' has an invalid URL: ${url}`);
555
581
  }
556
582
  const isLocalhost = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1";
557
583
  const isTestDomain = parsed.hostname.endsWith(".test");
558
584
  const allowedProtocol = parsed.protocol === "https:" || parsed.protocol === "http:" && (isLocalhost || isTestDomain);
559
585
  if (!allowedProtocol || parsed.username || parsed.password || parsed.search || parsed.hash || parsed.pathname !== "/" && parsed.pathname !== "") {
560
- throw new CliError(
561
- CliErrorCodes.ConfigInvalid,
586
+ throw new import_CliError.CliError(
587
+ import_CliError.CliErrorCodes.ConfigInvalid,
562
588
  `Environment '${name}' must be an HTTP(S) origin without credentials, path, query, or fragment.`
563
589
  );
564
590
  }
@@ -570,19 +596,19 @@ function validateEnvironment(env) {
570
596
  ["tokenEndpoint", env.tokenEndpoint]
571
597
  ]) {
572
598
  if (!url) {
573
- throw new CliError(CliErrorCodes.ConfigInvalid, `Environment '${env.name}' is missing ${field}.`);
599
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Environment '${env.name}' is missing ${field}.`);
574
600
  }
575
601
  requireHttpsOrTest(`${env.name}.${field}`, url);
576
602
  }
577
603
  if (!env.orchestratorUrl) {
578
- throw new CliError(CliErrorCodes.ConfigInvalid, `Environment '${env.name}' is missing orchestratorUrl.`);
604
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Environment '${env.name}' is missing orchestratorUrl.`);
579
605
  }
580
606
  requireHttpOrigin(`${env.name}.orchestratorUrl`, env.orchestratorUrl);
581
607
  if (!env.clientId) {
582
- throw new CliError(CliErrorCodes.ConfigInvalid, `Environment '${env.name}' is missing clientId.`);
608
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Environment '${env.name}' is missing clientId.`);
583
609
  }
584
610
  if (!env.redirectPath.startsWith("/")) {
585
- throw new CliError(CliErrorCodes.ConfigInvalid, `Environment '${env.name}' redirectPath must start with '/'.`);
611
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Environment '${env.name}' redirectPath must start with '/'.`);
586
612
  }
587
613
  }
588
614
  var ConfigStore = class {
@@ -607,7 +633,7 @@ var ConfigStore = class {
607
633
  try {
608
634
  raw = JSON.parse((0, import_node_fs.readFileSync)(this.path, "utf8"));
609
635
  } catch {
610
- throw new CliError(CliErrorCodes.ConfigInvalid, `Config file at ${this.path} is not valid JSON.`);
636
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.ConfigInvalid, `Config file at ${this.path} is not valid JSON.`);
611
637
  }
612
638
  const environments = Object.fromEntries(
613
639
  Object.entries({ ...DEFAULT_ENVIRONMENTS, ...raw.environments ?? {} }).map(([name, env]) => [
@@ -631,24 +657,24 @@ var ConfigStore = class {
631
657
  const config = this.load();
632
658
  const env = config.environments[config.activeEnvironment];
633
659
  if (!env) {
634
- throw new CliError(
635
- CliErrorCodes.EnvironmentNotFound,
660
+ throw new import_CliError.CliError(
661
+ import_CliError.CliErrorCodes.EnvironmentNotFound,
636
662
  `Active environment '${config.activeEnvironment}' is not defined. Run 'xyra env use <name>'.`
637
663
  );
638
664
  }
639
665
  validateEnvironment(env);
640
- if (env.accessPurpose !== void 0 || env.administrationTarget !== void 0) throw new CliError(
641
- CliErrorCodes.ConfigInvalid,
666
+ if (env.accessPurpose !== void 0 || env.administrationTarget !== void 0) throw new import_CliError.CliError(
667
+ import_CliError.CliErrorCodes.ConfigInvalid,
642
668
  "Purpose and selected administration target are invocation-only, not stored environment or actor fields."
643
669
  );
644
670
  const purpose = this.accessPurposeOverride ?? "runtime";
645
671
  if (!["runtime", "administration"].includes(purpose) || purpose === "runtime" && this.administrationTargetOverride !== void 0)
646
- throw new CliError(CliErrorCodes.InvalidArguments, "Select runtime or administration; a maintenance target requires administration purpose.");
672
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.InvalidArguments, "Select runtime or administration; a maintenance target requires administration purpose.");
647
673
  if (purpose === "runtime") return env;
648
674
  const profile = env.administrationOAuth;
649
675
  if (!profile || !profile.clientId || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,99}$/.test(profile.clientId) || profile.clientId === env.clientId || env.mcpUrl !== env.oauthResource || !Array.isArray(profile.scopes) || profile.scopes.length > 100 || !profile.scopes.includes("openid") || !profile.scopes.includes("offline_access") || profile.scopes.some((scope) => typeof scope !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(scope)) || !profile.redirectPath || !/^\/callback\/[A-Za-z0-9_-]+$/.test(profile.redirectPath))
650
- throw new CliError(
651
- CliErrorCodes.ConfigInvalid,
676
+ throw new import_CliError.CliError(
677
+ import_CliError.CliErrorCodes.ConfigInvalid,
652
678
  `Environment '${env.name}' needs its registered Xyra-owned public administration CLI profile.`,
653
679
  "Configure administrationOAuth with its separate native client, approved loopback callback path and delegated scopes; do not reuse the runtime or HTTPS connector client."
654
680
  );
@@ -656,18 +682,18 @@ var ConfigStore = class {
656
682
  try {
657
683
  selected = this.administrationTargetOverride === void 0 ? { targetKind: "global-resource", managedProductId: "xyra-ai" } : (0, import_canonical_runtime_json.parseBoundedRuntimeJsonV1)(this.administrationTargetOverride, { maximumBytes: 8192, maximumDepth: 4 });
658
684
  } catch {
659
- throw new CliError(CliErrorCodes.InvalidArguments, "The administration target must be one bounded JSON object without repeated fields.");
685
+ throw new import_CliError.CliError(import_CliError.CliErrorCodes.InvalidArguments, "The administration target must be one bounded JSON object without repeated fields.");
660
686
  }
661
687
  const target = (0, import_xyra_administration.parseXyraAdministrationTargetV1)(selected);
662
- if (!target) throw new CliError(CliErrorCodes.InvalidArguments, "Select one complete global, configuration-owner or customer administration target.");
688
+ if (!target) throw new import_CliError.CliError(import_CliError.CliErrorCodes.InvalidArguments, "Select one complete global, configuration-owner or customer administration target.");
663
689
  return { ...env, clientId: profile.clientId, redirectPath: profile.redirectPath, scopes: [...profile.scopes], accessPurpose: "administration", administrationTarget: target };
664
690
  }
665
691
  useEnvironment(name) {
666
692
  const config = this.load();
667
693
  const env = config.environments[name];
668
694
  if (!env) {
669
- throw new CliError(
670
- CliErrorCodes.EnvironmentNotFound,
695
+ throw new import_CliError.CliError(
696
+ import_CliError.CliErrorCodes.EnvironmentNotFound,
671
697
  `Environment '${name}' is not defined. Known: ${Object.keys(config.environments).join(", ")}.`
672
698
  );
673
699
  }