@andpipes/cli 0.1.2 → 0.1.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.
- package/README.md +5 -0
- package/dist/bin.cjs +578 -69
- package/dist/bin.js +1 -1
- package/dist/{chunk-ELZTOEAZ.js → chunk-6LTYTSZX.js} +549 -30
- package/dist/index.cjs +578 -69
- package/dist/index.d.cts +43 -2
- package/dist/index.d.ts +43 -2
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -51,6 +51,8 @@ import {
|
|
|
51
51
|
comparePublicationUnicodeCodePoints,
|
|
52
52
|
EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE,
|
|
53
53
|
externalSaasTemplateCommitment,
|
|
54
|
+
isOpenApiImportUpstreamAuthMode,
|
|
55
|
+
OpenApiImportError,
|
|
54
56
|
oauthClientScopeMapPlanCommitment,
|
|
55
57
|
onboardingTemplateApplicationCommitment,
|
|
56
58
|
onboardingTemplateBindingCommitment,
|
|
@@ -61,6 +63,7 @@ import {
|
|
|
61
63
|
parseOnboardingTemplateBindings,
|
|
62
64
|
parseOnboardingTemplateExportDto,
|
|
63
65
|
parseOnboardingTemplateSafePlanDto,
|
|
66
|
+
parseOpenApiImportOperationRiskOverrides,
|
|
64
67
|
parseToolContract,
|
|
65
68
|
publicationCommitment
|
|
66
69
|
} from "@andpipes/tool-contract";
|
|
@@ -561,12 +564,14 @@ var AdminApiClientError = class extends Error {
|
|
|
561
564
|
code;
|
|
562
565
|
status;
|
|
563
566
|
confirmationRequired;
|
|
564
|
-
|
|
567
|
+
openApiAuthModeMismatch;
|
|
568
|
+
constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch) {
|
|
565
569
|
super(message);
|
|
566
570
|
this.name = "AdminApiClientError";
|
|
567
571
|
this.code = code;
|
|
568
572
|
this.status = status;
|
|
569
573
|
this.confirmationRequired = confirmationRequired;
|
|
574
|
+
this.openApiAuthModeMismatch = openApiAuthModeMismatch;
|
|
570
575
|
}
|
|
571
576
|
};
|
|
572
577
|
function clientError(code, message, status) {
|
|
@@ -776,9 +781,27 @@ function withKnownResponseStatus(error, responseStatus) {
|
|
|
776
781
|
error.code,
|
|
777
782
|
error.message,
|
|
778
783
|
responseStatus,
|
|
779
|
-
error.confirmationRequired
|
|
784
|
+
error.confirmationRequired,
|
|
785
|
+
error.openApiAuthModeMismatch
|
|
780
786
|
);
|
|
781
787
|
}
|
|
788
|
+
var CONNECTOR_AUTH_MODES = /* @__PURE__ */ new Set([
|
|
789
|
+
"token_exchange",
|
|
790
|
+
"service_account",
|
|
791
|
+
"existing_oauth",
|
|
792
|
+
"signed_request"
|
|
793
|
+
]);
|
|
794
|
+
function parseOpenApiImportAuthModeMismatch(value) {
|
|
795
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
796
|
+
const details = value;
|
|
797
|
+
if (Object.keys(details).sort().join(",") !== "connectorAuthMode,reason,requestedAuthMode,supportedAuthModes" || details.reason !== "connector_auth_mode_mismatch" || typeof details.connectorAuthMode !== "string" || !CONNECTOR_AUTH_MODES.has(details.connectorAuthMode) || !isOpenApiImportUpstreamAuthMode(details.requestedAuthMode) || details.connectorAuthMode === details.requestedAuthMode) {
|
|
798
|
+
return void 0;
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
connectorAuthMode: details.connectorAuthMode,
|
|
802
|
+
requestedAuthMode: details.requestedAuthMode
|
|
803
|
+
};
|
|
804
|
+
}
|
|
782
805
|
function unicodeScalarLength(value) {
|
|
783
806
|
let length = 0;
|
|
784
807
|
for (const character of value) {
|
|
@@ -805,11 +828,13 @@ function safeApiError(status, value) {
|
|
|
805
828
|
const candidate = errorRecord?.code;
|
|
806
829
|
const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
|
|
807
830
|
const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
|
|
831
|
+
const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
|
|
808
832
|
return new AdminApiClientError(
|
|
809
833
|
code,
|
|
810
834
|
`Admin API request failed (${code}; HTTP ${status})`,
|
|
811
835
|
status,
|
|
812
|
-
confirmationRequired
|
|
836
|
+
confirmationRequired,
|
|
837
|
+
openApiAuthModeMismatch
|
|
813
838
|
);
|
|
814
839
|
}
|
|
815
840
|
function buildUrl(path) {
|
|
@@ -962,16 +987,38 @@ function publicationApplyBody(input) {
|
|
|
962
987
|
};
|
|
963
988
|
}
|
|
964
989
|
function openApiImportBody(input) {
|
|
965
|
-
if (typeof input.source !== "string" || input.source.length === 0 || !PUBLICATION_UUID_RE.test(input.connectorId) || input.expectedPlanCommitment !== void 0 && !SHA256_HEX_RE.test(input.expectedPlanCommitment) || input.format !== void 0 && input.format !== "json" && input.format !== "yaml" || input.baseUrl !== void 0 && typeof input.baseUrl !== "string" || input.serviceName !== void 0 && !/^[A-Za-z0-9_]{1,48}$/.test(input.serviceName)) {
|
|
990
|
+
if (typeof input.source !== "string" || input.source.length === 0 || !PUBLICATION_UUID_RE.test(input.connectorId) || input.expectedPlanCommitment !== void 0 && !SHA256_HEX_RE.test(input.expectedPlanCommitment) || input.format !== void 0 && input.format !== "json" && input.format !== "yaml" || input.baseUrl !== void 0 && typeof input.baseUrl !== "string" || input.serviceName !== void 0 && !/^[A-Za-z0-9_]{1,48}$/.test(input.serviceName) || input.upstreamAuthMode !== void 0 && !isOpenApiImportUpstreamAuthMode(input.upstreamAuthMode)) {
|
|
966
991
|
throw clientError("AP_INPUT_INVALID", "OpenAPI import request is invalid");
|
|
967
992
|
}
|
|
993
|
+
let operationRiskOverrides;
|
|
994
|
+
if (input.operationRiskOverrides !== void 0) {
|
|
995
|
+
try {
|
|
996
|
+
operationRiskOverrides = parseOpenApiImportOperationRiskOverrides(
|
|
997
|
+
input.operationRiskOverrides
|
|
998
|
+
);
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
if (error instanceof OpenApiImportError) {
|
|
1001
|
+
throw clientError("AP_INPUT_INVALID", "OpenAPI import request is invalid");
|
|
1002
|
+
}
|
|
1003
|
+
throw error;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
968
1006
|
return {
|
|
969
1007
|
source: input.source,
|
|
970
1008
|
connectorId: input.connectorId,
|
|
971
1009
|
...input.expectedPlanCommitment !== void 0 ? { expectedPlanCommitment: input.expectedPlanCommitment } : {},
|
|
972
1010
|
...input.format !== void 0 ? { format: input.format } : {},
|
|
973
1011
|
...input.baseUrl !== void 0 ? { baseUrl: input.baseUrl } : {},
|
|
974
|
-
...input.serviceName !== void 0 ? { serviceName: input.serviceName } : {}
|
|
1012
|
+
...input.serviceName !== void 0 ? { serviceName: input.serviceName } : {},
|
|
1013
|
+
...input.upstreamAuthMode !== void 0 ? { upstreamAuthMode: input.upstreamAuthMode } : {},
|
|
1014
|
+
...operationRiskOverrides !== void 0 ? {
|
|
1015
|
+
operationRiskOverrides: operationRiskOverrides.map((override) => ({
|
|
1016
|
+
toolName: override.toolName,
|
|
1017
|
+
method: override.method,
|
|
1018
|
+
path: override.path,
|
|
1019
|
+
riskLevel: override.riskLevel
|
|
1020
|
+
}))
|
|
1021
|
+
} : {}
|
|
975
1022
|
};
|
|
976
1023
|
}
|
|
977
1024
|
function parseSafeGateIssues(value, label) {
|
|
@@ -1647,6 +1694,15 @@ var AdminApiClient = class {
|
|
|
1647
1694
|
alignment: parseOAuthAlignmentSummary(value.alignment)
|
|
1648
1695
|
};
|
|
1649
1696
|
}
|
|
1697
|
+
async getUpstreamOAuthConnectionState(projectId, connectorId) {
|
|
1698
|
+
const project = assertProjectId(projectId);
|
|
1699
|
+
const connector = assertResourceId(connectorId, "--connector");
|
|
1700
|
+
return parseUpstreamOAuthConnectionState(
|
|
1701
|
+
await this.#request(
|
|
1702
|
+
`/v1/projects/${project}/connectors/${encodeURIComponent(connector)}/oauth-connection-state`
|
|
1703
|
+
)
|
|
1704
|
+
);
|
|
1705
|
+
}
|
|
1650
1706
|
async syncOAuthScopes(input) {
|
|
1651
1707
|
const value = asObject(
|
|
1652
1708
|
await this.#request(`/v1/projects/${assertProjectId(input.projectId)}/oauth/scopes:sync`, {
|
|
@@ -2334,6 +2390,228 @@ function parseOAuthAlignmentSummary(value) {
|
|
|
2334
2390
|
)
|
|
2335
2391
|
};
|
|
2336
2392
|
}
|
|
2393
|
+
function parseUpstreamOAuthConnectionState(value) {
|
|
2394
|
+
const label = "upstream OAuth connection state";
|
|
2395
|
+
const state = asObject(value, label);
|
|
2396
|
+
exactKeys(
|
|
2397
|
+
state,
|
|
2398
|
+
[
|
|
2399
|
+
"connectorId",
|
|
2400
|
+
"profile",
|
|
2401
|
+
"secretPresence",
|
|
2402
|
+
"links",
|
|
2403
|
+
"selectedLinkId",
|
|
2404
|
+
"mcpResource",
|
|
2405
|
+
"smokeTools",
|
|
2406
|
+
"requiredScopes",
|
|
2407
|
+
"scopes",
|
|
2408
|
+
"redirectUri",
|
|
2409
|
+
"diagnostics",
|
|
2410
|
+
"allGreen",
|
|
2411
|
+
"currentStep",
|
|
2412
|
+
"nextAction"
|
|
2413
|
+
],
|
|
2414
|
+
label
|
|
2415
|
+
);
|
|
2416
|
+
const newFields = ["selectedLinkId", "mcpResource", "smokeTools"];
|
|
2417
|
+
if (newFields.some((key) => Object.hasOwn(state, key)) && !newFields.every((key) => Object.hasOwn(state, key))) {
|
|
2418
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label} has incomplete fields`);
|
|
2419
|
+
}
|
|
2420
|
+
const connectorId = assertUuid(state.connectorId, `${label}.connectorId`);
|
|
2421
|
+
if (state.secretPresence !== "configured" && state.secretPresence !== "not_configured") {
|
|
2422
|
+
throw clientError(
|
|
2423
|
+
"AP_RESPONSE_INVALID",
|
|
2424
|
+
`Admin API response ${label}.secretPresence is invalid`
|
|
2425
|
+
);
|
|
2426
|
+
}
|
|
2427
|
+
let issuer = null;
|
|
2428
|
+
if (state.profile !== null) {
|
|
2429
|
+
const profile = asObject(state.profile, `${label}.profile`);
|
|
2430
|
+
exactKeys(
|
|
2431
|
+
profile,
|
|
2432
|
+
[
|
|
2433
|
+
"connectorId",
|
|
2434
|
+
"issuer",
|
|
2435
|
+
"authorizationEndpoint",
|
|
2436
|
+
"tokenEndpoint",
|
|
2437
|
+
"jwksUri",
|
|
2438
|
+
"introspectionEndpoint",
|
|
2439
|
+
"revocationEndpoint",
|
|
2440
|
+
"upstreamResource",
|
|
2441
|
+
"clientId",
|
|
2442
|
+
"allowedScopes",
|
|
2443
|
+
"generation",
|
|
2444
|
+
"status",
|
|
2445
|
+
"updatedAt"
|
|
2446
|
+
],
|
|
2447
|
+
`${label}.profile`
|
|
2448
|
+
);
|
|
2449
|
+
if (assertUuid(profile.connectorId, `${label}.profile.connectorId`) !== connectorId) {
|
|
2450
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.profile is unbound`);
|
|
2451
|
+
}
|
|
2452
|
+
issuer = stringField(profile, "issuer", `${label}.profile`);
|
|
2453
|
+
stringArrayField(profile, "allowedScopes", `${label}.profile`);
|
|
2454
|
+
}
|
|
2455
|
+
if (!Array.isArray(state.links)) {
|
|
2456
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.links is invalid`);
|
|
2457
|
+
}
|
|
2458
|
+
const hasSelection = Object.hasOwn(state, "selectedLinkId");
|
|
2459
|
+
const selectedLinkId = hasSelection ? nullableUuidField(state, "selectedLinkId", label) : null;
|
|
2460
|
+
let activeLink = false;
|
|
2461
|
+
let grantedScopes = [];
|
|
2462
|
+
let activeCount = 0;
|
|
2463
|
+
let selectedCount = 0;
|
|
2464
|
+
const linkIds = /* @__PURE__ */ new Set();
|
|
2465
|
+
for (const [index, entry] of state.links.entries()) {
|
|
2466
|
+
const linkLabel = `${label}.links[${index}]`;
|
|
2467
|
+
const link2 = asObject(entry, linkLabel);
|
|
2468
|
+
exactKeys(
|
|
2469
|
+
link2,
|
|
2470
|
+
[
|
|
2471
|
+
"id",
|
|
2472
|
+
"connectorId",
|
|
2473
|
+
"status",
|
|
2474
|
+
"grantedScopes",
|
|
2475
|
+
"accessExpiresAt",
|
|
2476
|
+
"refreshGeneration",
|
|
2477
|
+
"linkedAt",
|
|
2478
|
+
"refreshedAt",
|
|
2479
|
+
"revokedAt"
|
|
2480
|
+
],
|
|
2481
|
+
linkLabel
|
|
2482
|
+
);
|
|
2483
|
+
const linkId = assertUuid(link2.id, `${linkLabel}.id`);
|
|
2484
|
+
if (linkIds.has(linkId)) {
|
|
2485
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel}.id is duplicate`);
|
|
2486
|
+
}
|
|
2487
|
+
linkIds.add(linkId);
|
|
2488
|
+
if (assertUuid(link2.connectorId, `${linkLabel}.connectorId`) !== connectorId) {
|
|
2489
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel} is unbound`);
|
|
2490
|
+
}
|
|
2491
|
+
const status = stringField(link2, "status", linkLabel);
|
|
2492
|
+
if (!["active", "reconnect_required", "revoked", "expired"].includes(status)) {
|
|
2493
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel}.status is invalid`);
|
|
2494
|
+
}
|
|
2495
|
+
const scopes = stringArrayField(link2, "grantedScopes", linkLabel);
|
|
2496
|
+
if (status === "active") {
|
|
2497
|
+
activeCount += 1;
|
|
2498
|
+
if (hasSelection ? selectedLinkId === linkId : activeCount === 1) {
|
|
2499
|
+
activeLink = true;
|
|
2500
|
+
grantedScopes = scopes;
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
if (selectedLinkId === linkId) selectedCount += 1;
|
|
2504
|
+
}
|
|
2505
|
+
if (hasSelection && selectedLinkId !== null && (selectedCount !== 1 || !activeLink) || !hasSelection && activeCount > 1) {
|
|
2506
|
+
throw clientError(
|
|
2507
|
+
"AP_RESPONSE_INVALID",
|
|
2508
|
+
`Admin API response ${label}.selectedLinkId is invalid`
|
|
2509
|
+
);
|
|
2510
|
+
}
|
|
2511
|
+
if (hasSelection && selectedLinkId === null) {
|
|
2512
|
+
activeLink = false;
|
|
2513
|
+
grantedScopes = [];
|
|
2514
|
+
}
|
|
2515
|
+
const mcpResource = Object.hasOwn(state, "mcpResource") ? nullableStringField(state, "mcpResource", label) : null;
|
|
2516
|
+
if (mcpResource !== null) {
|
|
2517
|
+
let parsed;
|
|
2518
|
+
try {
|
|
2519
|
+
parsed = new URL(mcpResource);
|
|
2520
|
+
} catch {
|
|
2521
|
+
throw clientError(
|
|
2522
|
+
"AP_RESPONSE_INVALID",
|
|
2523
|
+
`Admin API response ${label}.mcpResource is invalid`
|
|
2524
|
+
);
|
|
2525
|
+
}
|
|
2526
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash || parsed.search) {
|
|
2527
|
+
throw clientError(
|
|
2528
|
+
"AP_RESPONSE_INVALID",
|
|
2529
|
+
`Admin API response ${label}.mcpResource is invalid`
|
|
2530
|
+
);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
const smokeToolsValue = Object.hasOwn(state, "smokeTools") ? state.smokeTools : [];
|
|
2534
|
+
if (!Array.isArray(smokeToolsValue)) {
|
|
2535
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.smokeTools is invalid`);
|
|
2536
|
+
}
|
|
2537
|
+
const smokeTools = smokeToolsValue.map(
|
|
2538
|
+
(entry, index) => {
|
|
2539
|
+
const toolLabel = `${label}.smokeTools[${index}]`;
|
|
2540
|
+
const tool = asObject(entry, toolLabel);
|
|
2541
|
+
exactRequiredKeys(tool, ["id", "versionId", "name", "scopes"], toolLabel);
|
|
2542
|
+
const name = stringField(tool, "name", toolLabel);
|
|
2543
|
+
const scopes = stringArrayField(tool, "scopes", toolLabel);
|
|
2544
|
+
if (!name || name.length > 256 || Array.from(name).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) || scopes.length === 0 || scopes.length > 100 || scopes.some((scope) => !/^[A-Za-z0-9._:-]{1,200}$/u.test(scope))) {
|
|
2545
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${toolLabel} is invalid`);
|
|
2546
|
+
}
|
|
2547
|
+
return {
|
|
2548
|
+
id: assertUuid(tool.id, `${toolLabel}.id`),
|
|
2549
|
+
versionId: assertUuid(tool.versionId, `${toolLabel}.versionId`),
|
|
2550
|
+
name,
|
|
2551
|
+
scopes
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
);
|
|
2555
|
+
if (!Array.isArray(state.scopes) || !Array.isArray(state.diagnostics)) {
|
|
2556
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label} is invalid`);
|
|
2557
|
+
}
|
|
2558
|
+
for (const [index, entry] of state.scopes.entries()) {
|
|
2559
|
+
const scopeLabel = `${label}.scopes[${index}]`;
|
|
2560
|
+
const scope = asObject(entry, scopeLabel);
|
|
2561
|
+
exactKeys(scope, ["name", "description", "riskLevel", "required"], scopeLabel);
|
|
2562
|
+
stringField(scope, "name", scopeLabel);
|
|
2563
|
+
if (scope.description !== null) stringField(scope, "description", scopeLabel);
|
|
2564
|
+
stringField(scope, "riskLevel", scopeLabel);
|
|
2565
|
+
booleanField(scope, "required", scopeLabel);
|
|
2566
|
+
}
|
|
2567
|
+
const diagnostics = state.diagnostics.map(
|
|
2568
|
+
(entry, index) => {
|
|
2569
|
+
const diagnosticLabel = `${label}.diagnostics[${index}]`;
|
|
2570
|
+
const diagnostic = asObject(entry, diagnosticLabel);
|
|
2571
|
+
exactKeys(diagnostic, ["id", "status", "detail"], diagnosticLabel);
|
|
2572
|
+
const status = diagnostic.status;
|
|
2573
|
+
if (status !== "pass" && status !== "pending" && status !== "fail") {
|
|
2574
|
+
throw clientError(
|
|
2575
|
+
"AP_RESPONSE_INVALID",
|
|
2576
|
+
`Admin API response ${diagnosticLabel} is invalid`
|
|
2577
|
+
);
|
|
2578
|
+
}
|
|
2579
|
+
return {
|
|
2580
|
+
id: stringField(diagnostic, "id", diagnosticLabel),
|
|
2581
|
+
status,
|
|
2582
|
+
detail: stringField(diagnostic, "detail", diagnosticLabel)
|
|
2583
|
+
};
|
|
2584
|
+
}
|
|
2585
|
+
);
|
|
2586
|
+
if (state.currentStep !== "metadata" && state.currentStep !== "test_account" && state.currentStep !== "diagnostics") {
|
|
2587
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.currentStep is invalid`);
|
|
2588
|
+
}
|
|
2589
|
+
if (state.nextAction !== "discover_metadata" && state.nextAction !== "link_test_account" && state.nextAction !== "fix_diagnostics" && state.nextAction !== "configure_custom_domain" && state.nextAction !== "publish_read_tool" && state.nextAction !== "run_customer_api_smoke" && state.nextAction !== "continue_to_chatgpt") {
|
|
2590
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.nextAction is invalid`);
|
|
2591
|
+
}
|
|
2592
|
+
const allGreen = booleanField(state, "allGreen", label);
|
|
2593
|
+
if (allGreen !== diagnostics.every((candidate) => candidate.status === "pass")) {
|
|
2594
|
+
throw clientError(
|
|
2595
|
+
"AP_RESPONSE_INVALID",
|
|
2596
|
+
`Admin API response ${label}.allGreen is inconsistent`
|
|
2597
|
+
);
|
|
2598
|
+
}
|
|
2599
|
+
return {
|
|
2600
|
+
connectorId,
|
|
2601
|
+
issuer,
|
|
2602
|
+
selectedLinkId,
|
|
2603
|
+
activeLink,
|
|
2604
|
+
mcpResource,
|
|
2605
|
+
smokeTools,
|
|
2606
|
+
requiredScopes: stringArrayField(state, "requiredScopes", label),
|
|
2607
|
+
grantedScopes,
|
|
2608
|
+
redirectUri: nullableStringField(state, "redirectUri", label),
|
|
2609
|
+
diagnostics,
|
|
2610
|
+
allGreen,
|
|
2611
|
+
currentStep: state.currentStep,
|
|
2612
|
+
nextAction: state.nextAction
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2337
2615
|
function nullableNonnegativeIntegerField(record, key, label) {
|
|
2338
2616
|
const value = record[key];
|
|
2339
2617
|
if (value === null) {
|
|
@@ -5548,7 +5826,7 @@ import {
|
|
|
5548
5826
|
EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
5549
5827
|
importOpenApi,
|
|
5550
5828
|
OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
5551
|
-
OpenApiImportError
|
|
5829
|
+
OpenApiImportError as OpenApiImportError2
|
|
5552
5830
|
} from "@andpipes/tool-contract";
|
|
5553
5831
|
|
|
5554
5832
|
// src/lib/init-manifest.ts
|
|
@@ -6082,6 +6360,96 @@ function writeInitManifestNoReplace(plan, manifest, runtime) {
|
|
|
6082
6360
|
});
|
|
6083
6361
|
}
|
|
6084
6362
|
|
|
6363
|
+
// src/lib/openapi-classification.ts
|
|
6364
|
+
import {
|
|
6365
|
+
isOpenApiImportUpstreamAuthMode as isOpenApiImportUpstreamAuthMode2,
|
|
6366
|
+
OPENAPI_IMPORT_MAX_OPERATIONS
|
|
6367
|
+
} from "@andpipes/tool-contract";
|
|
6368
|
+
var SIDE_EFFECT_FREE_RE = /^([A-Za-z0-9][A-Za-z0-9._:-]{0,199})=(read|draft)$/u;
|
|
6369
|
+
function parseAuthModeOption(value) {
|
|
6370
|
+
if (value === void 0) return void 0;
|
|
6371
|
+
if (!isOpenApiImportUpstreamAuthMode2(value)) {
|
|
6372
|
+
throw new UsageError("--auth-mode \u306F existing_oauth \u307E\u305F\u306F token_exchange \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
6373
|
+
}
|
|
6374
|
+
return value;
|
|
6375
|
+
}
|
|
6376
|
+
function parseSideEffectFreeOptions(values) {
|
|
6377
|
+
if (values === void 0 || values.length === 0) return [];
|
|
6378
|
+
if (values.length > OPENAPI_IMPORT_MAX_OPERATIONS) {
|
|
6379
|
+
throw new UsageError(
|
|
6380
|
+
`--side-effect-free \u306F${OPENAPI_IMPORT_MAX_OPERATIONS}\u4EF6\u4EE5\u4E0B\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`
|
|
6381
|
+
);
|
|
6382
|
+
}
|
|
6383
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6384
|
+
return values.map((value) => {
|
|
6385
|
+
const match = SIDE_EFFECT_FREE_RE.exec(value);
|
|
6386
|
+
if (!match?.[1] || !match[2]) {
|
|
6387
|
+
throw new UsageError(
|
|
6388
|
+
"--side-effect-free \u306F <toolName>=read \u307E\u305F\u306F <toolName>=draft \u306E\u5F62\u5F0F\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
6389
|
+
);
|
|
6390
|
+
}
|
|
6391
|
+
if (seen.has(match[1])) {
|
|
6392
|
+
throw new UsageError(`--side-effect-free \u3067\u540C\u3058tool\u540D\u3092\u91CD\u8907\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${match[1]}`);
|
|
6393
|
+
}
|
|
6394
|
+
seen.add(match[1]);
|
|
6395
|
+
return { toolName: match[1], riskLevel: match[2] };
|
|
6396
|
+
});
|
|
6397
|
+
}
|
|
6398
|
+
function postOperationList(operations) {
|
|
6399
|
+
const posts = operations.filter((operation) => operation.method === "POST");
|
|
6400
|
+
return posts.length === 0 ? " \uFF08POST\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF09" : posts.map((operation) => ` - ${operation.toolName} (POST ${operation.path})`).join("\n");
|
|
6401
|
+
}
|
|
6402
|
+
function resolveOperationRiskOverrides(requests, operations) {
|
|
6403
|
+
return requests.map((request) => {
|
|
6404
|
+
const operation = operations.find((candidate) => candidate.toolName === request.toolName);
|
|
6405
|
+
if (operation?.method !== "POST") {
|
|
6406
|
+
throw new UsageError(
|
|
6407
|
+
`--side-effect-free \u306F\u3053\u306EOpenAPI\u306EPOST\u64CD\u4F5C\u3060\u3051\u306B\u6307\u5B9A\u3067\u304D\u307E\u3059: ${request.toolName}
|
|
6408
|
+
\u6307\u5B9A\u3067\u304D\u308BPOST\u64CD\u4F5C:
|
|
6409
|
+
${postOperationList(operations)}`
|
|
6410
|
+
);
|
|
6411
|
+
}
|
|
6412
|
+
return {
|
|
6413
|
+
toolName: operation.toolName,
|
|
6414
|
+
method: "POST",
|
|
6415
|
+
path: operation.path,
|
|
6416
|
+
riskLevel: request.riskLevel
|
|
6417
|
+
};
|
|
6418
|
+
});
|
|
6419
|
+
}
|
|
6420
|
+
function sideEffectFreeGuidance(operations) {
|
|
6421
|
+
const defaults = operations.filter(
|
|
6422
|
+
(operation) => operation.method === "POST" && operation.riskLevel === "write_high"
|
|
6423
|
+
);
|
|
6424
|
+
const first = defaults[0];
|
|
6425
|
+
if (!first) return void 0;
|
|
6426
|
+
return [
|
|
6427
|
+
"\u6B21\u306EPOST\u64CD\u4F5C\u306F\u65E2\u5B9A\u306E\u300C\u66F4\u65B0\u300D\uFF08write_high: AI\u306E\u5B9F\u884C\u524D\u306B\u78BA\u8A8D\u3068\u51AA\u7B49key\u304C\u5FC5\u8981\uFF09\u306B\u5206\u985E\u3055\u308C\u3066\u3044\u307E\u3059\u3002",
|
|
6428
|
+
...defaults.map((operation) => ` - ${operation.toolName} (POST ${operation.path})`),
|
|
6429
|
+
"\u9867\u5BA2SaaS\u306E\u30C7\u30FC\u30BF\u3092\u4FDD\u5B58\u30FB\u5909\u66F4\u30FB\u9001\u4FE1\u3057\u306A\u3044POST\u3060\u3051\u3001API\u4ED5\u69D8\u307E\u305F\u306F\u5B9F\u88C5\u3067\u78BA\u8A8D\u3057\u3066\u304B\u3089\u6B21\u3092\u8FFD\u52A0\u3057\u3066\u518D\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
|
|
6430
|
+
" \u53C2\u7167\u3060\u3051\uFF08\u691C\u7D22\u30FB\u5DEE\u5206\u8A08\u7B97\u306A\u3069\uFF09: --side-effect-free <toolName>=read",
|
|
6431
|
+
" \u6848\u3092\u4F5C\u308B\u3060\u3051\uFF08\u53CD\u6620\u306F\u5225\u306E\u66F4\u65B0\u64CD\u4F5C\uFF09: --side-effect-free <toolName>=draft",
|
|
6432
|
+
` \u4F8B: --side-effect-free ${first.toolName}=read`
|
|
6433
|
+
].join("\n");
|
|
6434
|
+
}
|
|
6435
|
+
function authModeMismatchGuidance(mismatch) {
|
|
6436
|
+
const lines = [
|
|
6437
|
+
`connector\u306E\u8A8D\u8A3C\u65B9\u5F0F\uFF08${mismatch.connectorAuthMode}\uFF09\u3068\u53D6\u8FBC\u306E\u8A8D\u8A3C\u65B9\u5F0F\uFF08${mismatch.requestedAuthMode}\uFF09\u304C\u4E00\u81F4\u3057\u306A\u3044\u305F\u3081\u3001\u4E0B\u66F8\u304D\u3092\u4F5C\u3089\u305A\u306B\u505C\u6B62\u3057\u307E\u3057\u305F\u3002`
|
|
6438
|
+
];
|
|
6439
|
+
if (isOpenApiImportUpstreamAuthMode2(mismatch.connectorAuthMode)) {
|
|
6440
|
+
lines.push(
|
|
6441
|
+
` 1. \u3053\u306Econnector\u3092\u4F7F\u3046: --auth-mode ${mismatch.connectorAuthMode} \u3092\u6307\u5B9A\u3057\u3066\u518D\u5B9F\u884C\u3059\u308B`,
|
|
6442
|
+
` 2. \u53D6\u8FBC\u65B9\u5F0F\u3092\u5909\u3048\u306A\u3044: ${mismatch.requestedAuthMode} \u306Econnector\u3092 --connector \u306B\u6307\u5B9A\u3059\u308B`
|
|
6443
|
+
);
|
|
6444
|
+
} else {
|
|
6445
|
+
lines.push(
|
|
6446
|
+
" OpenAPI\u53D6\u8FBC\u306F existing_oauth \u307E\u305F\u306F token_exchange \u306Econnector\u3060\u3051\u3092\u5BFE\u8C61\u306B\u3067\u304D\u307E\u3059\u3002",
|
|
6447
|
+
" \u65E2\u5B58OAuth\u63A5\u7D9A\uFF08\u63A8\u5968\uFF09\u306FWeb Admin\u306EOAuth\u63A5\u7D9A\u30A6\u30A3\u30B6\u30FC\u30C9\u3067\u4F5C\u6210\u3057\u3001\u305D\u306Econnector\u3092 --connector \u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
|
|
6448
|
+
);
|
|
6449
|
+
}
|
|
6450
|
+
return lines.join("\n");
|
|
6451
|
+
}
|
|
6452
|
+
|
|
6085
6453
|
// src/lib/terminal-safe.ts
|
|
6086
6454
|
function isBidirectionalFormatControl(codePoint) {
|
|
6087
6455
|
return codePoint === 1564 || codePoint >= 8206 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
@@ -6449,8 +6817,13 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
6449
6817
|
if (options.openapi !== void 0 && options.project === void 0) {
|
|
6450
6818
|
throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
|
|
6451
6819
|
}
|
|
6452
|
-
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
|
|
6453
|
-
throw new UsageError(
|
|
6820
|
+
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0 || options.authMode !== void 0 || (options.sideEffectFree?.length ?? 0) > 0)) {
|
|
6821
|
+
throw new UsageError(
|
|
6822
|
+
messages.optionRequires(
|
|
6823
|
+
"--base-url / --service-name / --auth-mode / --side-effect-free",
|
|
6824
|
+
"--openapi"
|
|
6825
|
+
)
|
|
6826
|
+
);
|
|
6454
6827
|
}
|
|
6455
6828
|
if (options.openapi !== void 0 && (options.template !== void 0 || options.contract !== void 0 || options.create === true || options.name !== void 0 || options.slug !== void 0 || options.connector !== void 0 || options.createConnector === true)) {
|
|
6456
6829
|
throw new UsageError(
|
|
@@ -6475,7 +6848,9 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
6475
6848
|
}
|
|
6476
6849
|
}
|
|
6477
6850
|
async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
6478
|
-
if (options.openapi === void 0) return { options, anchor };
|
|
6851
|
+
if (options.openapi === void 0) return { options, anchor, notices: [] };
|
|
6852
|
+
const upstreamAuthMode = parseAuthModeOption(options.authMode);
|
|
6853
|
+
const sideEffectFree = parseSideEffectFreeOptions(options.sideEffectFree);
|
|
6479
6854
|
const contractPath = "tool-contract.json";
|
|
6480
6855
|
prepareLocalOrThrow(runtime, anchor, contractPath, messages);
|
|
6481
6856
|
const source = withAnchoredLocalRoot(
|
|
@@ -6488,13 +6863,21 @@ async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
|
6488
6863
|
);
|
|
6489
6864
|
let imported;
|
|
6490
6865
|
try {
|
|
6491
|
-
|
|
6866
|
+
const importOptions = {
|
|
6492
6867
|
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
6493
6868
|
...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
|
|
6494
|
-
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
|
|
6495
|
-
|
|
6869
|
+
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName },
|
|
6870
|
+
...upstreamAuthMode === void 0 ? {} : { upstreamAuthMode }
|
|
6871
|
+
};
|
|
6872
|
+
imported = importOpenApi(source.text, importOptions);
|
|
6873
|
+
if (sideEffectFree.length > 0) {
|
|
6874
|
+
imported = importOpenApi(source.text, {
|
|
6875
|
+
...importOptions,
|
|
6876
|
+
operationRiskOverrides: resolveOperationRiskOverrides(sideEffectFree, imported.operations)
|
|
6877
|
+
});
|
|
6878
|
+
}
|
|
6496
6879
|
} catch (error) {
|
|
6497
|
-
if (error instanceof
|
|
6880
|
+
if (error instanceof OpenApiImportError2) {
|
|
6498
6881
|
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
6499
6882
|
}
|
|
6500
6883
|
throw error;
|
|
@@ -6539,13 +6922,27 @@ async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
|
6539
6922
|
messages.failure("local_file_changed")
|
|
6540
6923
|
);
|
|
6541
6924
|
}
|
|
6925
|
+
const notices = [];
|
|
6926
|
+
if (upstreamAuthMode === void 0) {
|
|
6927
|
+
notices.push(
|
|
6928
|
+
"\u8A8D\u8A3C\u65B9\u5F0F: token_exchange\uFF08\u65E2\u5B9A\uFF09\u3002Web Admin\u306EOAuth\u63A5\u7D9A\u30A6\u30A3\u30B6\u30FC\u30C9\u3067\u4F5C\u308B\u65E2\u5B58OAuth\u63A5\u7D9A\uFF08existing_oauth\uFF09\u3078\u516C\u958B\u3059\u308B\u5834\u5408\u306F\u3001\u751F\u6210\u6E08\u307F\u306Etool-contract.json\u3092\u9000\u907F\u3057\u3066\u304B\u3089 --auth-mode existing_oauth \u3092\u4ED8\u3051\u3066\u518D\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
|
|
6929
|
+
);
|
|
6930
|
+
}
|
|
6931
|
+
const guidance = sideEffectFreeGuidance(imported.operations);
|
|
6932
|
+
if (guidance) {
|
|
6933
|
+
notices.push(
|
|
6934
|
+
`${guidance}
|
|
6935
|
+
tool-contract.json\u306F\u4E0A\u66F8\u304D\u3057\u306A\u3044\u305F\u3081\u3001\u5206\u985E\u3092\u5909\u3048\u3066\u518D\u751F\u6210\u3059\u308B\u5834\u5408\u306F\u751F\u6210\u6E08\u307Ffile\u3092\u9000\u907F\u3057\u3066\u304B\u3089\u518D\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
|
|
6936
|
+
);
|
|
6937
|
+
}
|
|
6542
6938
|
return {
|
|
6543
6939
|
options: {
|
|
6544
6940
|
project: options.project,
|
|
6545
6941
|
contract: contractPath,
|
|
6546
6942
|
profile: options.profile
|
|
6547
6943
|
},
|
|
6548
|
-
anchor: refreshedAnchor
|
|
6944
|
+
anchor: refreshedAnchor,
|
|
6945
|
+
notices
|
|
6549
6946
|
};
|
|
6550
6947
|
}
|
|
6551
6948
|
async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
@@ -7067,6 +7464,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7067
7464
|
const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
|
|
7068
7465
|
rootAnchor = materialized.anchor;
|
|
7069
7466
|
mode = normalizeInitOptions(materialized.options, messages);
|
|
7467
|
+
for (const notice of materialized.notices) interactive(writer, notice);
|
|
7070
7468
|
}
|
|
7071
7469
|
if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
|
|
7072
7470
|
let actionMode;
|
|
@@ -7170,6 +7568,14 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7170
7568
|
function registerInit(program, writer, cwd, createClient, description2 = "Project\u3092\u660E\u793A\u9078\u629E\u307E\u305F\u306F\u4F5C\u6210\u3057\u3001\u5B89\u5168\u306Alocal manifest\u3078bind\u3057\u307E\u3059", runtime = void 0, messages = DEFAULT_INIT_MESSAGES) {
|
|
7171
7569
|
const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
|
|
7172
7570
|
program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option("--openapi <file>", messages.openApiOption).option("--base-url <https-url>", messages.openApiBaseUrlOption).option("--service-name <name>", messages.openApiServiceNameOption).option(
|
|
7571
|
+
"--auth-mode <mode>",
|
|
7572
|
+
"OpenAPI upstream auth mode matching the publish connector: existing_oauth or token_exchange (default token_exchange)"
|
|
7573
|
+
).option(
|
|
7574
|
+
"--side-effect-free <toolName=level>",
|
|
7575
|
+
"Explicitly classify a POST that does not store, change or send data as read or draft (repeatable)",
|
|
7576
|
+
(value, previous) => [...previous, value],
|
|
7577
|
+
[]
|
|
7578
|
+
).option(
|
|
7173
7579
|
"--create-connector",
|
|
7174
7580
|
"Create the template connector through the existing Admin API policy boundary",
|
|
7175
7581
|
false
|
|
@@ -7277,6 +7683,14 @@ function buildInitTemplate(provider) {
|
|
|
7277
7683
|
scopes: ["openid", "profile"]
|
|
7278
7684
|
};
|
|
7279
7685
|
}
|
|
7686
|
+
function upstreamOAuthWizardUrl(profile, projectId, connectorId) {
|
|
7687
|
+
const record = getProfile(profile);
|
|
7688
|
+
if (!record)
|
|
7689
|
+
throw new UsageError(`\u8A8D\u8A3Cprofile ${profile} \u304C\u3042\u308A\u307E\u305B\u3093\u3002andpipe login\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044`);
|
|
7690
|
+
const url = new URL(`/projects/${projectId}/oauth`, new URL(record.verificationUriBase).origin);
|
|
7691
|
+
url.searchParams.set("connector", connectorId);
|
|
7692
|
+
return url.toString();
|
|
7693
|
+
}
|
|
7280
7694
|
async function loadOAuthMetadata(opts, locale) {
|
|
7281
7695
|
const messages = CLI_MESSAGES8[locale];
|
|
7282
7696
|
if (opts.file && opts.issuer) {
|
|
@@ -7306,7 +7720,7 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
7306
7720
|
info(writer, messages.oauth.metadataOk);
|
|
7307
7721
|
}
|
|
7308
7722
|
}
|
|
7309
|
-
function registerOauth(program, writer, locale = DEFAULT_LOCALE7) {
|
|
7723
|
+
function registerOauth(program, writer, locale = DEFAULT_LOCALE7, dependencies = {}) {
|
|
7310
7724
|
const messages = CLI_MESSAGES8[locale];
|
|
7311
7725
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
7312
7726
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
@@ -7387,6 +7801,43 @@ function registerOauth(program, writer, locale = DEFAULT_LOCALE7) {
|
|
|
7387
7801
|
metadata.command("validate").description(messages.oauth.validateDescription).option("--file <path>", messages.common.metadataFileOption).option("--issuer <url>", messages.common.issuerOption).action(async (opts) => {
|
|
7388
7802
|
await runOAuthMetadataValidate(opts, writer, locale);
|
|
7389
7803
|
});
|
|
7804
|
+
const connect = oauth.command("connect").description(
|
|
7805
|
+
locale === "ja" ? "\u9867\u5BA2SaaS\u306EOAuth account linking\u3092Web Admin\u3068\u540C\u3058\u72B6\u614B\u3067\u8A2D\u5B9A" : "Configure customer SaaS OAuth account linking with shared Web Admin state"
|
|
7806
|
+
);
|
|
7807
|
+
connect.command("status").description(
|
|
7808
|
+
locale === "ja" ? "\u63A5\u7D9A\u72B6\u614B\u3068\u6B21\u306E\u64CD\u4F5C\u3092\u8868\u793A" : "Show connection state and next action"
|
|
7809
|
+
).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--connector <connector>", "\u63A5\u7D9A\u5BFE\u8C61connector UUID").option("--profile <name>", messages.common.targetProfileOption, DEFAULT_PROFILE_NAME).action(async (opts) => {
|
|
7810
|
+
const state = await createAdminApiClient({
|
|
7811
|
+
profile: opts.profile
|
|
7812
|
+
}).getUpstreamOAuthConnectionState(assertProjectId(opts.project), opts.connector);
|
|
7813
|
+
json(writer, state);
|
|
7814
|
+
if (!state.allGreen) process.exitCode = 1;
|
|
7815
|
+
});
|
|
7816
|
+
connect.command("open").description(
|
|
7817
|
+
locale === "ja" ? "\u540C\u3058\u63A5\u7D9A\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3066Web Admin\u30A6\u30A3\u30B6\u30FC\u30C9\u3092\u958B\u304F" : "Check shared state and open the Web Admin wizard"
|
|
7818
|
+
).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--connector <connector>", "\u63A5\u7D9A\u5BFE\u8C61connector UUID").option("--profile <name>", messages.common.targetProfileOption, DEFAULT_PROFILE_NAME).option(
|
|
7819
|
+
"--no-browser",
|
|
7820
|
+
locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u958B\u304B\u305AURL\u3060\u3051\u8868\u793A" : "Print the URL without opening a browser"
|
|
7821
|
+
).action(
|
|
7822
|
+
async (opts) => {
|
|
7823
|
+
const projectId = assertProjectId(opts.project);
|
|
7824
|
+
const state = await createAdminApiClient({
|
|
7825
|
+
profile: opts.profile
|
|
7826
|
+
}).getUpstreamOAuthConnectionState(projectId, opts.connector);
|
|
7827
|
+
json(writer, state);
|
|
7828
|
+
const url = upstreamOAuthWizardUrl(opts.profile, projectId, opts.connector);
|
|
7829
|
+
info(
|
|
7830
|
+
writer,
|
|
7831
|
+
locale === "ja" ? `Web Admin\u3067\u7D9A\u3051\u3066\u304F\u3060\u3055\u3044: ${url}` : `Continue in Web Admin: ${url}`
|
|
7832
|
+
);
|
|
7833
|
+
if (opts.browser) {
|
|
7834
|
+
try {
|
|
7835
|
+
(dependencies.openBrowser ?? openBrowser)(url);
|
|
7836
|
+
} catch {
|
|
7837
|
+
}
|
|
7838
|
+
}
|
|
7839
|
+
}
|
|
7840
|
+
);
|
|
7390
7841
|
oauth.command("test-login").description(messages.oauth.testLoginDescription).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--client <client-registry-uuid>", "\u691C\u67FB\u5BFE\u8C61\u306Eproject OAuth client registry ID").option("--profile <name>", messages.common.targetProfileOption, DEFAULT_PROFILE_NAME).action(async (opts) => {
|
|
7391
7842
|
const projectId = assertProjectId(opts.project);
|
|
7392
7843
|
const result = await createAdminApiClient({ profile: opts.profile }).testOAuthLogin(
|
|
@@ -7401,7 +7852,11 @@ function registerOauth(program, writer, locale = DEFAULT_LOCALE7) {
|
|
|
7401
7852
|
// src/commands/openapi.ts
|
|
7402
7853
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
7403
7854
|
import { resolve as resolve4 } from "path";
|
|
7404
|
-
import {
|
|
7855
|
+
import {
|
|
7856
|
+
importOpenApi as importOpenApi2,
|
|
7857
|
+
OPENAPI_IMPORT_MAX_SOURCE_BYTES as OPENAPI_IMPORT_MAX_SOURCE_BYTES2,
|
|
7858
|
+
OpenApiImportError as OpenApiImportError3
|
|
7859
|
+
} from "@andpipes/tool-contract";
|
|
7405
7860
|
function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
7406
7861
|
return { createClient, idempotencyKey: randomUUID6 };
|
|
7407
7862
|
}
|
|
@@ -7437,9 +7892,17 @@ function normalizedOptions(options) {
|
|
|
7437
7892
|
apply,
|
|
7438
7893
|
yes,
|
|
7439
7894
|
...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
|
|
7440
|
-
...options.planCommitment !== void 0 ? { planCommitment: options.planCommitment } : {}
|
|
7895
|
+
...options.planCommitment !== void 0 ? { planCommitment: options.planCommitment } : {},
|
|
7896
|
+
...options.authMode !== void 0 ? { upstreamAuthMode: parseAuthModeOption(options.authMode) } : {},
|
|
7897
|
+
sideEffectFree: parseSideEffectFreeOptions(options.sideEffectFree)
|
|
7441
7898
|
};
|
|
7442
7899
|
}
|
|
7900
|
+
function rethrowWithAuthModeGuidance(error) {
|
|
7901
|
+
if (error instanceof AdminApiClientError && error.openApiAuthModeMismatch) {
|
|
7902
|
+
throw new UsageError(authModeMismatchGuidance(error.openApiAuthModeMismatch));
|
|
7903
|
+
}
|
|
7904
|
+
throw error;
|
|
7905
|
+
}
|
|
7443
7906
|
async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
7444
7907
|
const normalized = normalizedOptions(options);
|
|
7445
7908
|
if (normalized.apply && !normalized.yes) {
|
|
@@ -7455,36 +7918,85 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
7455
7918
|
maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES2,
|
|
7456
7919
|
root: cwd
|
|
7457
7920
|
});
|
|
7458
|
-
const
|
|
7921
|
+
const baseRequest = {
|
|
7459
7922
|
source: snapshot.text,
|
|
7460
7923
|
connectorId: normalized.connectorId,
|
|
7461
7924
|
...normalized.format !== void 0 ? { format: normalized.format } : {},
|
|
7462
7925
|
...normalized.baseUrl !== void 0 ? { baseUrl: normalized.baseUrl } : {},
|
|
7463
7926
|
...normalized.serviceName !== void 0 ? { serviceName: normalized.serviceName } : {},
|
|
7464
|
-
...normalized.
|
|
7927
|
+
...normalized.upstreamAuthMode !== void 0 ? { upstreamAuthMode: normalized.upstreamAuthMode } : {}
|
|
7465
7928
|
};
|
|
7466
7929
|
const client = runtime.createClient(normalized.profile);
|
|
7467
|
-
|
|
7468
|
-
|
|
7469
|
-
if (result2.sourceCommitment !== snapshot.sha256) {
|
|
7930
|
+
const assertSource = (sourceCommitment) => {
|
|
7931
|
+
if (sourceCommitment !== snapshot.sha256) {
|
|
7470
7932
|
throw new UsageError("Admin API\u306Esource commitment\u304Clocal file\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
7471
7933
|
}
|
|
7472
|
-
|
|
7934
|
+
};
|
|
7935
|
+
let overrides = [];
|
|
7936
|
+
if (normalized.sideEffectFree.length > 0) {
|
|
7937
|
+
if (normalized.apply) {
|
|
7938
|
+
try {
|
|
7939
|
+
const unclassified = importOpenApi2(snapshot.text, {
|
|
7940
|
+
format: normalized.format,
|
|
7941
|
+
baseUrl: normalized.baseUrl,
|
|
7942
|
+
serviceName: normalized.serviceName,
|
|
7943
|
+
upstreamAuthMode: normalized.upstreamAuthMode
|
|
7944
|
+
});
|
|
7945
|
+
overrides = resolveOperationRiskOverrides(
|
|
7946
|
+
normalized.sideEffectFree,
|
|
7947
|
+
unclassified.operations
|
|
7948
|
+
);
|
|
7949
|
+
} catch (error) {
|
|
7950
|
+
if (error instanceof OpenApiImportError3) {
|
|
7951
|
+
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
7952
|
+
}
|
|
7953
|
+
throw error;
|
|
7954
|
+
}
|
|
7955
|
+
} else {
|
|
7956
|
+
const unclassified = await client.planOpenApiImport(normalized.project, baseRequest).catch(rethrowWithAuthModeGuidance);
|
|
7957
|
+
assertSource(unclassified.sourceCommitment);
|
|
7958
|
+
overrides = resolveOperationRiskOverrides(normalized.sideEffectFree, unclassified.operations);
|
|
7959
|
+
}
|
|
7960
|
+
}
|
|
7961
|
+
const request = {
|
|
7962
|
+
...baseRequest,
|
|
7963
|
+
...overrides.length > 0 ? { operationRiskOverrides: overrides } : {},
|
|
7964
|
+
...normalized.planCommitment !== void 0 ? { expectedPlanCommitment: normalized.planCommitment } : {}
|
|
7965
|
+
};
|
|
7966
|
+
const classification = {
|
|
7967
|
+
upstreamAuthMode: normalized.upstreamAuthMode ?? "token_exchange",
|
|
7968
|
+
operationRiskOverrides: overrides
|
|
7969
|
+
};
|
|
7970
|
+
if (!normalized.apply) {
|
|
7971
|
+
const result2 = await client.planOpenApiImport(normalized.project, request).catch(rethrowWithAuthModeGuidance);
|
|
7972
|
+
assertSource(result2.sourceCommitment);
|
|
7973
|
+
json(writer, { mode: "preview", ...classification, ...result2 });
|
|
7974
|
+
const guidance = sideEffectFreeGuidance(result2.operations);
|
|
7975
|
+
if (guidance) interactive(writer, guidance);
|
|
7473
7976
|
return;
|
|
7474
7977
|
}
|
|
7475
7978
|
const result = await client.applyOpenApiImport(
|
|
7476
7979
|
normalized.project,
|
|
7477
7980
|
normalized.idempotencyKey ?? runtime.idempotencyKey(),
|
|
7478
7981
|
request
|
|
7479
|
-
);
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7982
|
+
).catch(rethrowWithAuthModeGuidance);
|
|
7983
|
+
assertSource(result.sourceCommitment);
|
|
7984
|
+
json(writer, { mode: "draft_created", ...classification, ...result });
|
|
7985
|
+
}
|
|
7986
|
+
function collect(value, previous) {
|
|
7987
|
+
return [...previous, value];
|
|
7484
7988
|
}
|
|
7485
7989
|
function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
7486
7990
|
const openapi = program.command("openapi").description("OpenAPI\u304B\u3089Tool Contract draft\u3092\u63D0\u6848\u3059\u308B");
|
|
7487
|
-
openapi.command("import").description("OpenAPI 3.0/3.1 file\u3092\u5B89\u5168\u306Bpreview\u307E\u305F\u306Fdraft\u5316\u3059\u308B").requiredOption("--file <path>", "project root\u5185\u306EOpenAPI JSON/YAML file").requiredOption("--project <uuid>", "\u5BFE\u8C61project UUID").requiredOption("--connector <uuid>", "draft\u3092\u675F\u7E1B\u3059\u308Bactive connector UUID").option("--profile <name>", "Admin CLI profile", DEFAULT_PROFILE_NAME).option("--format <format>", "json\u307E\u305F\u306Fyaml\uFF08\u7701\u7565\u6642\u306F\u81EA\u52D5\u5224\u5B9A\uFF09").option("--base-url <url>", "document servers\u3092\u4E0A\u66F8\u304D\u3059\u308BHTTPS public base URL").option("--service-name <name>", "fallback tool/scope\u306Eservice\u540D").option("--apply", "preview\u6E08\u307Fproposal\u3092draft\u3068\u3057\u3066\u4FDD\u5B58\u3059\u308B", false).option("--yes", "draft\u4F5C\u6210\u3092\u660E\u793A\u78BA\u8A8D\u3059\u308B", false).option("--idempotency-key <key>", "\u518D\u9001\u7528Idempotency-Key").option("--plan-commitment <sha256>", "preview\u3067\u5F97\u305Fsafe plan commitment").
|
|
7991
|
+
openapi.command("import").description("OpenAPI 3.0/3.1 file\u3092\u5B89\u5168\u306Bpreview\u307E\u305F\u306Fdraft\u5316\u3059\u308B").requiredOption("--file <path>", "project root\u5185\u306EOpenAPI JSON/YAML file").requiredOption("--project <uuid>", "\u5BFE\u8C61project UUID").requiredOption("--connector <uuid>", "draft\u3092\u675F\u7E1B\u3059\u308Bactive connector UUID").option("--profile <name>", "Admin CLI profile", DEFAULT_PROFILE_NAME).option("--format <format>", "json\u307E\u305F\u306Fyaml\uFF08\u7701\u7565\u6642\u306F\u81EA\u52D5\u5224\u5B9A\uFF09").option("--base-url <url>", "document servers\u3092\u4E0A\u66F8\u304D\u3059\u308BHTTPS public base URL").option("--service-name <name>", "fallback tool/scope\u306Eservice\u540D").option("--apply", "preview\u6E08\u307Fproposal\u3092draft\u3068\u3057\u3066\u4FDD\u5B58\u3059\u308B", false).option("--yes", "draft\u4F5C\u6210\u3092\u660E\u793A\u78BA\u8A8D\u3059\u308B", false).option("--idempotency-key <key>", "\u518D\u9001\u7528Idempotency-Key").option("--plan-commitment <sha256>", "preview\u3067\u5F97\u305Fsafe plan commitment").option(
|
|
7992
|
+
"--auth-mode <mode>",
|
|
7993
|
+
"connector\u3068\u540C\u3058\u8A8D\u8A3C\u65B9\u5F0F\uFF08existing_oauth \u307E\u305F\u306F token_exchange\u3002\u7701\u7565\u6642\u306Ftoken_exchange\uFF09"
|
|
7994
|
+
).option(
|
|
7995
|
+
"--side-effect-free <toolName=level>",
|
|
7996
|
+
"\u30C7\u30FC\u30BF\u3092\u4FDD\u5B58\u30FB\u5909\u66F4\u30FB\u9001\u4FE1\u3057\u306A\u3044POST\u3060\u3051\u3092read\u307E\u305F\u306Fdraft\u3078\u660E\u793A\u5206\u985E\u3059\u308B\uFF08\u7E70\u308A\u8FD4\u3057\u6307\u5B9A\u53EF\uFF09",
|
|
7997
|
+
collect,
|
|
7998
|
+
[]
|
|
7999
|
+
).action(
|
|
7488
8000
|
(options) => runOpenApiImportCommand(options, writer, cwd(), runtime)
|
|
7489
8001
|
);
|
|
7490
8002
|
}
|
|
@@ -7711,7 +8223,11 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
7711
8223
|
}
|
|
7712
8224
|
const toolBlockedReasons = new Set(tools.flatMap((tool) => tool.blockedReasons));
|
|
7713
8225
|
if (tools.some((tool) => !tool.gate.ok) && plan.applyAllowed || tools.some((tool) => tool.opaqueChanged) && (plan.applyAllowed || !blockedReasons.includes("opaque_change")) || TOOL_BLOCKED_REASONS.some(
|
|
7714
|
-
(reason) =>
|
|
8226
|
+
(reason) => (
|
|
8227
|
+
// connector_mismatchはtool単位(既存toolの別connector束縛)に加え、candidateの
|
|
8228
|
+
// upstream.auth.modeとconnector方式の不一致としてtop-levelだけにも出る (#456 / #724)。
|
|
8229
|
+
reason === "connector_mismatch" ? toolBlockedReasons.has(reason) && !blockedReasons.includes(reason) : blockedReasons.includes(reason) !== toolBlockedReasons.has(reason)
|
|
8230
|
+
)
|
|
7715
8231
|
)) {
|
|
7716
8232
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
7717
8233
|
}
|
|
@@ -8165,6 +8681,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8165
8681
|
messages
|
|
8166
8682
|
);
|
|
8167
8683
|
writePlan(writer, plan);
|
|
8684
|
+
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
8685
|
+
interactive(writer, messages.connectorMismatchRemediation);
|
|
8686
|
+
}
|
|
8168
8687
|
if (normalized.mode === "dry-run") return;
|
|
8169
8688
|
if (!plan.applyAllowed) {
|
|
8170
8689
|
throw new PublishCommandError(
|