@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
package/dist/index.cjs
CHANGED
|
@@ -635,12 +635,14 @@ var AdminApiClientError = class extends Error {
|
|
|
635
635
|
code;
|
|
636
636
|
status;
|
|
637
637
|
confirmationRequired;
|
|
638
|
-
|
|
638
|
+
openApiAuthModeMismatch;
|
|
639
|
+
constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch) {
|
|
639
640
|
super(message);
|
|
640
641
|
this.name = "AdminApiClientError";
|
|
641
642
|
this.code = code;
|
|
642
643
|
this.status = status;
|
|
643
644
|
this.confirmationRequired = confirmationRequired;
|
|
645
|
+
this.openApiAuthModeMismatch = openApiAuthModeMismatch;
|
|
644
646
|
}
|
|
645
647
|
};
|
|
646
648
|
function clientError(code, message, status) {
|
|
@@ -850,9 +852,27 @@ function withKnownResponseStatus(error, responseStatus) {
|
|
|
850
852
|
error.code,
|
|
851
853
|
error.message,
|
|
852
854
|
responseStatus,
|
|
853
|
-
error.confirmationRequired
|
|
855
|
+
error.confirmationRequired,
|
|
856
|
+
error.openApiAuthModeMismatch
|
|
854
857
|
);
|
|
855
858
|
}
|
|
859
|
+
var CONNECTOR_AUTH_MODES = /* @__PURE__ */ new Set([
|
|
860
|
+
"token_exchange",
|
|
861
|
+
"service_account",
|
|
862
|
+
"existing_oauth",
|
|
863
|
+
"signed_request"
|
|
864
|
+
]);
|
|
865
|
+
function parseOpenApiImportAuthModeMismatch(value) {
|
|
866
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
867
|
+
const details = value;
|
|
868
|
+
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) || !(0, import_tool_contract.isOpenApiImportUpstreamAuthMode)(details.requestedAuthMode) || details.connectorAuthMode === details.requestedAuthMode) {
|
|
869
|
+
return void 0;
|
|
870
|
+
}
|
|
871
|
+
return {
|
|
872
|
+
connectorAuthMode: details.connectorAuthMode,
|
|
873
|
+
requestedAuthMode: details.requestedAuthMode
|
|
874
|
+
};
|
|
875
|
+
}
|
|
856
876
|
function unicodeScalarLength(value) {
|
|
857
877
|
let length = 0;
|
|
858
878
|
for (const character of value) {
|
|
@@ -879,11 +899,13 @@ function safeApiError(status, value) {
|
|
|
879
899
|
const candidate = errorRecord?.code;
|
|
880
900
|
const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
|
|
881
901
|
const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
|
|
902
|
+
const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
|
|
882
903
|
return new AdminApiClientError(
|
|
883
904
|
code,
|
|
884
905
|
`Admin API request failed (${code}; HTTP ${status})`,
|
|
885
906
|
status,
|
|
886
|
-
confirmationRequired
|
|
907
|
+
confirmationRequired,
|
|
908
|
+
openApiAuthModeMismatch
|
|
887
909
|
);
|
|
888
910
|
}
|
|
889
911
|
function buildUrl(path) {
|
|
@@ -1036,16 +1058,38 @@ function publicationApplyBody(input) {
|
|
|
1036
1058
|
};
|
|
1037
1059
|
}
|
|
1038
1060
|
function openApiImportBody(input) {
|
|
1039
|
-
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)) {
|
|
1061
|
+
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 && !(0, import_tool_contract.isOpenApiImportUpstreamAuthMode)(input.upstreamAuthMode)) {
|
|
1040
1062
|
throw clientError("AP_INPUT_INVALID", "OpenAPI import request is invalid");
|
|
1041
1063
|
}
|
|
1064
|
+
let operationRiskOverrides;
|
|
1065
|
+
if (input.operationRiskOverrides !== void 0) {
|
|
1066
|
+
try {
|
|
1067
|
+
operationRiskOverrides = (0, import_tool_contract.parseOpenApiImportOperationRiskOverrides)(
|
|
1068
|
+
input.operationRiskOverrides
|
|
1069
|
+
);
|
|
1070
|
+
} catch (error) {
|
|
1071
|
+
if (error instanceof import_tool_contract.OpenApiImportError) {
|
|
1072
|
+
throw clientError("AP_INPUT_INVALID", "OpenAPI import request is invalid");
|
|
1073
|
+
}
|
|
1074
|
+
throw error;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1042
1077
|
return {
|
|
1043
1078
|
source: input.source,
|
|
1044
1079
|
connectorId: input.connectorId,
|
|
1045
1080
|
...input.expectedPlanCommitment !== void 0 ? { expectedPlanCommitment: input.expectedPlanCommitment } : {},
|
|
1046
1081
|
...input.format !== void 0 ? { format: input.format } : {},
|
|
1047
1082
|
...input.baseUrl !== void 0 ? { baseUrl: input.baseUrl } : {},
|
|
1048
|
-
...input.serviceName !== void 0 ? { serviceName: input.serviceName } : {}
|
|
1083
|
+
...input.serviceName !== void 0 ? { serviceName: input.serviceName } : {},
|
|
1084
|
+
...input.upstreamAuthMode !== void 0 ? { upstreamAuthMode: input.upstreamAuthMode } : {},
|
|
1085
|
+
...operationRiskOverrides !== void 0 ? {
|
|
1086
|
+
operationRiskOverrides: operationRiskOverrides.map((override) => ({
|
|
1087
|
+
toolName: override.toolName,
|
|
1088
|
+
method: override.method,
|
|
1089
|
+
path: override.path,
|
|
1090
|
+
riskLevel: override.riskLevel
|
|
1091
|
+
}))
|
|
1092
|
+
} : {}
|
|
1049
1093
|
};
|
|
1050
1094
|
}
|
|
1051
1095
|
function parseSafeGateIssues(value, label) {
|
|
@@ -1721,6 +1765,15 @@ var AdminApiClient = class {
|
|
|
1721
1765
|
alignment: parseOAuthAlignmentSummary(value.alignment)
|
|
1722
1766
|
};
|
|
1723
1767
|
}
|
|
1768
|
+
async getUpstreamOAuthConnectionState(projectId, connectorId) {
|
|
1769
|
+
const project = assertProjectId(projectId);
|
|
1770
|
+
const connector = assertResourceId(connectorId, "--connector");
|
|
1771
|
+
return parseUpstreamOAuthConnectionState(
|
|
1772
|
+
await this.#request(
|
|
1773
|
+
`/v1/projects/${project}/connectors/${encodeURIComponent(connector)}/oauth-connection-state`
|
|
1774
|
+
)
|
|
1775
|
+
);
|
|
1776
|
+
}
|
|
1724
1777
|
async syncOAuthScopes(input) {
|
|
1725
1778
|
const value = asObject(
|
|
1726
1779
|
await this.#request(`/v1/projects/${assertProjectId(input.projectId)}/oauth/scopes:sync`, {
|
|
@@ -2408,6 +2461,228 @@ function parseOAuthAlignmentSummary(value) {
|
|
|
2408
2461
|
)
|
|
2409
2462
|
};
|
|
2410
2463
|
}
|
|
2464
|
+
function parseUpstreamOAuthConnectionState(value) {
|
|
2465
|
+
const label = "upstream OAuth connection state";
|
|
2466
|
+
const state = asObject(value, label);
|
|
2467
|
+
exactKeys(
|
|
2468
|
+
state,
|
|
2469
|
+
[
|
|
2470
|
+
"connectorId",
|
|
2471
|
+
"profile",
|
|
2472
|
+
"secretPresence",
|
|
2473
|
+
"links",
|
|
2474
|
+
"selectedLinkId",
|
|
2475
|
+
"mcpResource",
|
|
2476
|
+
"smokeTools",
|
|
2477
|
+
"requiredScopes",
|
|
2478
|
+
"scopes",
|
|
2479
|
+
"redirectUri",
|
|
2480
|
+
"diagnostics",
|
|
2481
|
+
"allGreen",
|
|
2482
|
+
"currentStep",
|
|
2483
|
+
"nextAction"
|
|
2484
|
+
],
|
|
2485
|
+
label
|
|
2486
|
+
);
|
|
2487
|
+
const newFields = ["selectedLinkId", "mcpResource", "smokeTools"];
|
|
2488
|
+
if (newFields.some((key) => Object.hasOwn(state, key)) && !newFields.every((key) => Object.hasOwn(state, key))) {
|
|
2489
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label} has incomplete fields`);
|
|
2490
|
+
}
|
|
2491
|
+
const connectorId = assertUuid(state.connectorId, `${label}.connectorId`);
|
|
2492
|
+
if (state.secretPresence !== "configured" && state.secretPresence !== "not_configured") {
|
|
2493
|
+
throw clientError(
|
|
2494
|
+
"AP_RESPONSE_INVALID",
|
|
2495
|
+
`Admin API response ${label}.secretPresence is invalid`
|
|
2496
|
+
);
|
|
2497
|
+
}
|
|
2498
|
+
let issuer = null;
|
|
2499
|
+
if (state.profile !== null) {
|
|
2500
|
+
const profile = asObject(state.profile, `${label}.profile`);
|
|
2501
|
+
exactKeys(
|
|
2502
|
+
profile,
|
|
2503
|
+
[
|
|
2504
|
+
"connectorId",
|
|
2505
|
+
"issuer",
|
|
2506
|
+
"authorizationEndpoint",
|
|
2507
|
+
"tokenEndpoint",
|
|
2508
|
+
"jwksUri",
|
|
2509
|
+
"introspectionEndpoint",
|
|
2510
|
+
"revocationEndpoint",
|
|
2511
|
+
"upstreamResource",
|
|
2512
|
+
"clientId",
|
|
2513
|
+
"allowedScopes",
|
|
2514
|
+
"generation",
|
|
2515
|
+
"status",
|
|
2516
|
+
"updatedAt"
|
|
2517
|
+
],
|
|
2518
|
+
`${label}.profile`
|
|
2519
|
+
);
|
|
2520
|
+
if (assertUuid(profile.connectorId, `${label}.profile.connectorId`) !== connectorId) {
|
|
2521
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.profile is unbound`);
|
|
2522
|
+
}
|
|
2523
|
+
issuer = stringField(profile, "issuer", `${label}.profile`);
|
|
2524
|
+
stringArrayField(profile, "allowedScopes", `${label}.profile`);
|
|
2525
|
+
}
|
|
2526
|
+
if (!Array.isArray(state.links)) {
|
|
2527
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.links is invalid`);
|
|
2528
|
+
}
|
|
2529
|
+
const hasSelection = Object.hasOwn(state, "selectedLinkId");
|
|
2530
|
+
const selectedLinkId = hasSelection ? nullableUuidField(state, "selectedLinkId", label) : null;
|
|
2531
|
+
let activeLink = false;
|
|
2532
|
+
let grantedScopes = [];
|
|
2533
|
+
let activeCount = 0;
|
|
2534
|
+
let selectedCount = 0;
|
|
2535
|
+
const linkIds = /* @__PURE__ */ new Set();
|
|
2536
|
+
for (const [index, entry] of state.links.entries()) {
|
|
2537
|
+
const linkLabel = `${label}.links[${index}]`;
|
|
2538
|
+
const link2 = asObject(entry, linkLabel);
|
|
2539
|
+
exactKeys(
|
|
2540
|
+
link2,
|
|
2541
|
+
[
|
|
2542
|
+
"id",
|
|
2543
|
+
"connectorId",
|
|
2544
|
+
"status",
|
|
2545
|
+
"grantedScopes",
|
|
2546
|
+
"accessExpiresAt",
|
|
2547
|
+
"refreshGeneration",
|
|
2548
|
+
"linkedAt",
|
|
2549
|
+
"refreshedAt",
|
|
2550
|
+
"revokedAt"
|
|
2551
|
+
],
|
|
2552
|
+
linkLabel
|
|
2553
|
+
);
|
|
2554
|
+
const linkId = assertUuid(link2.id, `${linkLabel}.id`);
|
|
2555
|
+
if (linkIds.has(linkId)) {
|
|
2556
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel}.id is duplicate`);
|
|
2557
|
+
}
|
|
2558
|
+
linkIds.add(linkId);
|
|
2559
|
+
if (assertUuid(link2.connectorId, `${linkLabel}.connectorId`) !== connectorId) {
|
|
2560
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel} is unbound`);
|
|
2561
|
+
}
|
|
2562
|
+
const status = stringField(link2, "status", linkLabel);
|
|
2563
|
+
if (!["active", "reconnect_required", "revoked", "expired"].includes(status)) {
|
|
2564
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel}.status is invalid`);
|
|
2565
|
+
}
|
|
2566
|
+
const scopes = stringArrayField(link2, "grantedScopes", linkLabel);
|
|
2567
|
+
if (status === "active") {
|
|
2568
|
+
activeCount += 1;
|
|
2569
|
+
if (hasSelection ? selectedLinkId === linkId : activeCount === 1) {
|
|
2570
|
+
activeLink = true;
|
|
2571
|
+
grantedScopes = scopes;
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
if (selectedLinkId === linkId) selectedCount += 1;
|
|
2575
|
+
}
|
|
2576
|
+
if (hasSelection && selectedLinkId !== null && (selectedCount !== 1 || !activeLink) || !hasSelection && activeCount > 1) {
|
|
2577
|
+
throw clientError(
|
|
2578
|
+
"AP_RESPONSE_INVALID",
|
|
2579
|
+
`Admin API response ${label}.selectedLinkId is invalid`
|
|
2580
|
+
);
|
|
2581
|
+
}
|
|
2582
|
+
if (hasSelection && selectedLinkId === null) {
|
|
2583
|
+
activeLink = false;
|
|
2584
|
+
grantedScopes = [];
|
|
2585
|
+
}
|
|
2586
|
+
const mcpResource = Object.hasOwn(state, "mcpResource") ? nullableStringField(state, "mcpResource", label) : null;
|
|
2587
|
+
if (mcpResource !== null) {
|
|
2588
|
+
let parsed;
|
|
2589
|
+
try {
|
|
2590
|
+
parsed = new URL(mcpResource);
|
|
2591
|
+
} catch {
|
|
2592
|
+
throw clientError(
|
|
2593
|
+
"AP_RESPONSE_INVALID",
|
|
2594
|
+
`Admin API response ${label}.mcpResource is invalid`
|
|
2595
|
+
);
|
|
2596
|
+
}
|
|
2597
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash || parsed.search) {
|
|
2598
|
+
throw clientError(
|
|
2599
|
+
"AP_RESPONSE_INVALID",
|
|
2600
|
+
`Admin API response ${label}.mcpResource is invalid`
|
|
2601
|
+
);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
const smokeToolsValue = Object.hasOwn(state, "smokeTools") ? state.smokeTools : [];
|
|
2605
|
+
if (!Array.isArray(smokeToolsValue)) {
|
|
2606
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.smokeTools is invalid`);
|
|
2607
|
+
}
|
|
2608
|
+
const smokeTools = smokeToolsValue.map(
|
|
2609
|
+
(entry, index) => {
|
|
2610
|
+
const toolLabel = `${label}.smokeTools[${index}]`;
|
|
2611
|
+
const tool = asObject(entry, toolLabel);
|
|
2612
|
+
exactRequiredKeys(tool, ["id", "versionId", "name", "scopes"], toolLabel);
|
|
2613
|
+
const name = stringField(tool, "name", toolLabel);
|
|
2614
|
+
const scopes = stringArrayField(tool, "scopes", toolLabel);
|
|
2615
|
+
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))) {
|
|
2616
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${toolLabel} is invalid`);
|
|
2617
|
+
}
|
|
2618
|
+
return {
|
|
2619
|
+
id: assertUuid(tool.id, `${toolLabel}.id`),
|
|
2620
|
+
versionId: assertUuid(tool.versionId, `${toolLabel}.versionId`),
|
|
2621
|
+
name,
|
|
2622
|
+
scopes
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
);
|
|
2626
|
+
if (!Array.isArray(state.scopes) || !Array.isArray(state.diagnostics)) {
|
|
2627
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label} is invalid`);
|
|
2628
|
+
}
|
|
2629
|
+
for (const [index, entry] of state.scopes.entries()) {
|
|
2630
|
+
const scopeLabel = `${label}.scopes[${index}]`;
|
|
2631
|
+
const scope = asObject(entry, scopeLabel);
|
|
2632
|
+
exactKeys(scope, ["name", "description", "riskLevel", "required"], scopeLabel);
|
|
2633
|
+
stringField(scope, "name", scopeLabel);
|
|
2634
|
+
if (scope.description !== null) stringField(scope, "description", scopeLabel);
|
|
2635
|
+
stringField(scope, "riskLevel", scopeLabel);
|
|
2636
|
+
booleanField(scope, "required", scopeLabel);
|
|
2637
|
+
}
|
|
2638
|
+
const diagnostics = state.diagnostics.map(
|
|
2639
|
+
(entry, index) => {
|
|
2640
|
+
const diagnosticLabel = `${label}.diagnostics[${index}]`;
|
|
2641
|
+
const diagnostic = asObject(entry, diagnosticLabel);
|
|
2642
|
+
exactKeys(diagnostic, ["id", "status", "detail"], diagnosticLabel);
|
|
2643
|
+
const status = diagnostic.status;
|
|
2644
|
+
if (status !== "pass" && status !== "pending" && status !== "fail") {
|
|
2645
|
+
throw clientError(
|
|
2646
|
+
"AP_RESPONSE_INVALID",
|
|
2647
|
+
`Admin API response ${diagnosticLabel} is invalid`
|
|
2648
|
+
);
|
|
2649
|
+
}
|
|
2650
|
+
return {
|
|
2651
|
+
id: stringField(diagnostic, "id", diagnosticLabel),
|
|
2652
|
+
status,
|
|
2653
|
+
detail: stringField(diagnostic, "detail", diagnosticLabel)
|
|
2654
|
+
};
|
|
2655
|
+
}
|
|
2656
|
+
);
|
|
2657
|
+
if (state.currentStep !== "metadata" && state.currentStep !== "test_account" && state.currentStep !== "diagnostics") {
|
|
2658
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.currentStep is invalid`);
|
|
2659
|
+
}
|
|
2660
|
+
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") {
|
|
2661
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.nextAction is invalid`);
|
|
2662
|
+
}
|
|
2663
|
+
const allGreen = booleanField(state, "allGreen", label);
|
|
2664
|
+
if (allGreen !== diagnostics.every((candidate) => candidate.status === "pass")) {
|
|
2665
|
+
throw clientError(
|
|
2666
|
+
"AP_RESPONSE_INVALID",
|
|
2667
|
+
`Admin API response ${label}.allGreen is inconsistent`
|
|
2668
|
+
);
|
|
2669
|
+
}
|
|
2670
|
+
return {
|
|
2671
|
+
connectorId,
|
|
2672
|
+
issuer,
|
|
2673
|
+
selectedLinkId,
|
|
2674
|
+
activeLink,
|
|
2675
|
+
mcpResource,
|
|
2676
|
+
smokeTools,
|
|
2677
|
+
requiredScopes: stringArrayField(state, "requiredScopes", label),
|
|
2678
|
+
grantedScopes,
|
|
2679
|
+
redirectUri: nullableStringField(state, "redirectUri", label),
|
|
2680
|
+
diagnostics,
|
|
2681
|
+
allGreen,
|
|
2682
|
+
currentStep: state.currentStep,
|
|
2683
|
+
nextAction: state.nextAction
|
|
2684
|
+
};
|
|
2685
|
+
}
|
|
2411
2686
|
function nullableNonnegativeIntegerField(record, key, label) {
|
|
2412
2687
|
const value = record[key];
|
|
2413
2688
|
if (value === null) {
|
|
@@ -6235,7 +6510,7 @@ var import_node_crypto11 = require("crypto");
|
|
|
6235
6510
|
var import_node_path11 = require("path");
|
|
6236
6511
|
var import_promises2 = require("readline/promises");
|
|
6237
6512
|
var import_localization7 = require("@andpipes/localization");
|
|
6238
|
-
var
|
|
6513
|
+
var import_tool_contract8 = require("@andpipes/tool-contract");
|
|
6239
6514
|
|
|
6240
6515
|
// src/lib/init-manifest.ts
|
|
6241
6516
|
var import_node_fs10 = require("fs");
|
|
@@ -6758,6 +7033,93 @@ function writeInitManifestNoReplace(plan, manifest, runtime) {
|
|
|
6758
7033
|
});
|
|
6759
7034
|
}
|
|
6760
7035
|
|
|
7036
|
+
// src/lib/openapi-classification.ts
|
|
7037
|
+
var import_tool_contract6 = require("@andpipes/tool-contract");
|
|
7038
|
+
var SIDE_EFFECT_FREE_RE = /^([A-Za-z0-9][A-Za-z0-9._:-]{0,199})=(read|draft)$/u;
|
|
7039
|
+
function parseAuthModeOption(value) {
|
|
7040
|
+
if (value === void 0) return void 0;
|
|
7041
|
+
if (!(0, import_tool_contract6.isOpenApiImportUpstreamAuthMode)(value)) {
|
|
7042
|
+
throw new UsageError("--auth-mode \u306F existing_oauth \u307E\u305F\u306F token_exchange \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
7043
|
+
}
|
|
7044
|
+
return value;
|
|
7045
|
+
}
|
|
7046
|
+
function parseSideEffectFreeOptions(values) {
|
|
7047
|
+
if (values === void 0 || values.length === 0) return [];
|
|
7048
|
+
if (values.length > import_tool_contract6.OPENAPI_IMPORT_MAX_OPERATIONS) {
|
|
7049
|
+
throw new UsageError(
|
|
7050
|
+
`--side-effect-free \u306F${import_tool_contract6.OPENAPI_IMPORT_MAX_OPERATIONS}\u4EF6\u4EE5\u4E0B\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`
|
|
7051
|
+
);
|
|
7052
|
+
}
|
|
7053
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7054
|
+
return values.map((value) => {
|
|
7055
|
+
const match = SIDE_EFFECT_FREE_RE.exec(value);
|
|
7056
|
+
if (!match?.[1] || !match[2]) {
|
|
7057
|
+
throw new UsageError(
|
|
7058
|
+
"--side-effect-free \u306F <toolName>=read \u307E\u305F\u306F <toolName>=draft \u306E\u5F62\u5F0F\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
7059
|
+
);
|
|
7060
|
+
}
|
|
7061
|
+
if (seen.has(match[1])) {
|
|
7062
|
+
throw new UsageError(`--side-effect-free \u3067\u540C\u3058tool\u540D\u3092\u91CD\u8907\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${match[1]}`);
|
|
7063
|
+
}
|
|
7064
|
+
seen.add(match[1]);
|
|
7065
|
+
return { toolName: match[1], riskLevel: match[2] };
|
|
7066
|
+
});
|
|
7067
|
+
}
|
|
7068
|
+
function postOperationList(operations) {
|
|
7069
|
+
const posts = operations.filter((operation) => operation.method === "POST");
|
|
7070
|
+
return posts.length === 0 ? " \uFF08POST\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF09" : posts.map((operation) => ` - ${operation.toolName} (POST ${operation.path})`).join("\n");
|
|
7071
|
+
}
|
|
7072
|
+
function resolveOperationRiskOverrides(requests, operations) {
|
|
7073
|
+
return requests.map((request) => {
|
|
7074
|
+
const operation = operations.find((candidate) => candidate.toolName === request.toolName);
|
|
7075
|
+
if (operation?.method !== "POST") {
|
|
7076
|
+
throw new UsageError(
|
|
7077
|
+
`--side-effect-free \u306F\u3053\u306EOpenAPI\u306EPOST\u64CD\u4F5C\u3060\u3051\u306B\u6307\u5B9A\u3067\u304D\u307E\u3059: ${request.toolName}
|
|
7078
|
+
\u6307\u5B9A\u3067\u304D\u308BPOST\u64CD\u4F5C:
|
|
7079
|
+
${postOperationList(operations)}`
|
|
7080
|
+
);
|
|
7081
|
+
}
|
|
7082
|
+
return {
|
|
7083
|
+
toolName: operation.toolName,
|
|
7084
|
+
method: "POST",
|
|
7085
|
+
path: operation.path,
|
|
7086
|
+
riskLevel: request.riskLevel
|
|
7087
|
+
};
|
|
7088
|
+
});
|
|
7089
|
+
}
|
|
7090
|
+
function sideEffectFreeGuidance(operations) {
|
|
7091
|
+
const defaults = operations.filter(
|
|
7092
|
+
(operation) => operation.method === "POST" && operation.riskLevel === "write_high"
|
|
7093
|
+
);
|
|
7094
|
+
const first = defaults[0];
|
|
7095
|
+
if (!first) return void 0;
|
|
7096
|
+
return [
|
|
7097
|
+
"\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",
|
|
7098
|
+
...defaults.map((operation) => ` - ${operation.toolName} (POST ${operation.path})`),
|
|
7099
|
+
"\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",
|
|
7100
|
+
" \u53C2\u7167\u3060\u3051\uFF08\u691C\u7D22\u30FB\u5DEE\u5206\u8A08\u7B97\u306A\u3069\uFF09: --side-effect-free <toolName>=read",
|
|
7101
|
+
" \u6848\u3092\u4F5C\u308B\u3060\u3051\uFF08\u53CD\u6620\u306F\u5225\u306E\u66F4\u65B0\u64CD\u4F5C\uFF09: --side-effect-free <toolName>=draft",
|
|
7102
|
+
` \u4F8B: --side-effect-free ${first.toolName}=read`
|
|
7103
|
+
].join("\n");
|
|
7104
|
+
}
|
|
7105
|
+
function authModeMismatchGuidance(mismatch) {
|
|
7106
|
+
const lines = [
|
|
7107
|
+
`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`
|
|
7108
|
+
];
|
|
7109
|
+
if ((0, import_tool_contract6.isOpenApiImportUpstreamAuthMode)(mismatch.connectorAuthMode)) {
|
|
7110
|
+
lines.push(
|
|
7111
|
+
` 1. \u3053\u306Econnector\u3092\u4F7F\u3046: --auth-mode ${mismatch.connectorAuthMode} \u3092\u6307\u5B9A\u3057\u3066\u518D\u5B9F\u884C\u3059\u308B`,
|
|
7112
|
+
` 2. \u53D6\u8FBC\u65B9\u5F0F\u3092\u5909\u3048\u306A\u3044: ${mismatch.requestedAuthMode} \u306Econnector\u3092 --connector \u306B\u6307\u5B9A\u3059\u308B`
|
|
7113
|
+
);
|
|
7114
|
+
} else {
|
|
7115
|
+
lines.push(
|
|
7116
|
+
" OpenAPI\u53D6\u8FBC\u306F existing_oauth \u307E\u305F\u306F token_exchange \u306Econnector\u3060\u3051\u3092\u5BFE\u8C61\u306B\u3067\u304D\u307E\u3059\u3002",
|
|
7117
|
+
" \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"
|
|
7118
|
+
);
|
|
7119
|
+
}
|
|
7120
|
+
return lines.join("\n");
|
|
7121
|
+
}
|
|
7122
|
+
|
|
6761
7123
|
// src/lib/terminal-safe.ts
|
|
6762
7124
|
function isBidirectionalFormatControl(codePoint) {
|
|
6763
7125
|
return codePoint === 1564 || codePoint >= 8206 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
@@ -6794,7 +7156,7 @@ function terminalSafeValue(value) {
|
|
|
6794
7156
|
// src/commands/template.ts
|
|
6795
7157
|
var import_node_crypto10 = require("crypto");
|
|
6796
7158
|
var import_node_path10 = require("path");
|
|
6797
|
-
var
|
|
7159
|
+
var import_tool_contract7 = require("@andpipes/tool-contract");
|
|
6798
7160
|
var BINDINGS_MAX_BYTES = 64 * 1024;
|
|
6799
7161
|
var EXPORT_MAX_BYTES = 1280 * 1024;
|
|
6800
7162
|
var TEMPLATE_ID_RE2 = /^[a-z][a-z0-9._-]{0,63}$/u;
|
|
@@ -6802,7 +7164,7 @@ function createTemplateCommandRuntime(createClient = (profile) => createAdminApi
|
|
|
6802
7164
|
return { createClient, idempotencyKey: import_node_crypto10.randomUUID };
|
|
6803
7165
|
}
|
|
6804
7166
|
function jsonObject(text, label) {
|
|
6805
|
-
const parsed = (0,
|
|
7167
|
+
const parsed = (0, import_tool_contract7.parseToolContract)(text, { format: "json" });
|
|
6806
7168
|
if (!parsed.ok || !parsed.contract || typeof parsed.contract !== "object" || Array.isArray(parsed.contract)) {
|
|
6807
7169
|
throw new UsageError(`${label}\u306Fvalid JSON object\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
|
|
6808
7170
|
}
|
|
@@ -6829,7 +7191,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6829
7191
|
}
|
|
6830
7192
|
let exported;
|
|
6831
7193
|
try {
|
|
6832
|
-
exported = (0,
|
|
7194
|
+
exported = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(source);
|
|
6833
7195
|
} catch {
|
|
6834
7196
|
throw new UsageError("template export artifact\u306Eshape\u304C\u4E0D\u6B63\u3067\u3059");
|
|
6835
7197
|
}
|
|
@@ -6854,7 +7216,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6854
7216
|
}
|
|
6855
7217
|
const bindingSnapshot = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6856
7218
|
const bindingSource = jsonObject(bindingSnapshot.text, "bindings file");
|
|
6857
|
-
const manifest = (0,
|
|
7219
|
+
const manifest = (0, import_tool_contract7.parseExternalSaasTemplate)(source);
|
|
6858
7220
|
const verifiedTemplate = readArtifact(file, EXPORT_MAX_BYTES, "template file");
|
|
6859
7221
|
const verifiedBindings = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6860
7222
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template inputs final root");
|
|
@@ -6866,7 +7228,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6866
7228
|
}
|
|
6867
7229
|
return {
|
|
6868
7230
|
manifest,
|
|
6869
|
-
bindings: (0,
|
|
7231
|
+
bindings: (0, import_tool_contract7.parseOnboardingTemplateBindings)(manifest, bindingSource),
|
|
6870
7232
|
sourceSnapshot: { ...verifiedTemplate.identity, sha256: verifiedTemplate.sha256 }
|
|
6871
7233
|
};
|
|
6872
7234
|
} catch (error) {
|
|
@@ -6895,7 +7257,7 @@ function expectedCurrent(value) {
|
|
|
6895
7257
|
throw new UsageError("--apply\u306B\u306F--expected-current <commitment|none>\u304C\u5FC5\u9808\u3067\u3059");
|
|
6896
7258
|
}
|
|
6897
7259
|
if (value === "none") return null;
|
|
6898
|
-
if (!
|
|
7260
|
+
if (!import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(value)) {
|
|
6899
7261
|
throw new UsageError("--expected-current\u306Fsha256 commitment\u307E\u305F\u306Fnone\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
6900
7262
|
}
|
|
6901
7263
|
return value;
|
|
@@ -6915,7 +7277,7 @@ function applyProof(options) {
|
|
|
6915
7277
|
"\u5148\u306Bdry-run\u306Esafe diff\u3092\u78BA\u8A8D\u3057\u3001--apply --yes\u3067\u660E\u793A\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
6916
7278
|
);
|
|
6917
7279
|
}
|
|
6918
|
-
if (!options.planCommitment || !
|
|
7280
|
+
if (!options.planCommitment || !import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(options.planCommitment)) {
|
|
6919
7281
|
throw new UsageError("--apply\u306B\u306Fdry-run\u3067\u5F97\u305F--plan-commitment\u304C\u5FC5\u9808\u3067\u3059");
|
|
6920
7282
|
}
|
|
6921
7283
|
return {
|
|
@@ -6924,10 +7286,10 @@ function applyProof(options) {
|
|
|
6924
7286
|
};
|
|
6925
7287
|
}
|
|
6926
7288
|
function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
6927
|
-
const parsedPlan = (0,
|
|
6928
|
-
const templateCommitment = (0,
|
|
6929
|
-
const bindingCommitment = (0,
|
|
6930
|
-
const applicationCommitment = (0,
|
|
7289
|
+
const parsedPlan = (0, import_tool_contract7.parseOnboardingTemplateSafePlanDto)(plan);
|
|
7290
|
+
const templateCommitment = (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest);
|
|
7291
|
+
const bindingCommitment = (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings);
|
|
7292
|
+
const applicationCommitment = (0, import_tool_contract7.onboardingTemplateApplicationCommitment)({
|
|
6931
7293
|
projectId,
|
|
6932
7294
|
templateCommitment,
|
|
6933
7295
|
bindingCommitment
|
|
@@ -6937,10 +7299,10 @@ function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
|
6937
7299
|
}
|
|
6938
7300
|
}
|
|
6939
7301
|
function assertApplyMatchesLocal(result, projectId, loaded, planCommitment) {
|
|
6940
|
-
const parsed = (0,
|
|
6941
|
-
const templateCommitment = (0,
|
|
6942
|
-
const bindingCommitment = (0,
|
|
6943
|
-
const applicationCommitment = (0,
|
|
7302
|
+
const parsed = (0, import_tool_contract7.parseOnboardingTemplateApplyDto)(result);
|
|
7303
|
+
const templateCommitment = (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest);
|
|
7304
|
+
const bindingCommitment = (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings);
|
|
7305
|
+
const applicationCommitment = (0, import_tool_contract7.onboardingTemplateApplicationCommitment)({
|
|
6944
7306
|
projectId,
|
|
6945
7307
|
templateCommitment,
|
|
6946
7308
|
bindingCommitment
|
|
@@ -6990,7 +7352,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6990
7352
|
const client = runtime.createClient(options.profile ?? DEFAULT_PROFILE_NAME);
|
|
6991
7353
|
if (!proof) {
|
|
6992
7354
|
const plan = await client.planOnboardingTemplateRollback(projectId, templateId, targetRevision);
|
|
6993
|
-
const parsed2 = (0,
|
|
7355
|
+
const parsed2 = (0, import_tool_contract7.parseOnboardingTemplateSafePlanDto)(plan);
|
|
6994
7356
|
if (parsed2.projectId !== projectId || parsed2.templateId !== templateId || parsed2.operation !== "rollback" || parsed2.rollbackFromRevision !== targetRevision || parsed2.currentApplicationCommitment === null) {
|
|
6995
7357
|
throw new UsageError("Admin API\u306Erollback plan\u304C\u8981\u6C42scope\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6996
7358
|
}
|
|
@@ -7021,7 +7383,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
7021
7383
|
confirmed: true
|
|
7022
7384
|
}
|
|
7023
7385
|
);
|
|
7024
|
-
const parsed = (0,
|
|
7386
|
+
const parsed = (0, import_tool_contract7.parseOnboardingTemplateApplyDto)(result);
|
|
7025
7387
|
if (parsed.projectId !== projectId || parsed.templateId !== templateId || parsed.operation !== "rollback" || parsed.rollbackFromRevision !== targetRevision || parsed.planCommitment !== proof.planCommitment || parsed.applicationCommitment === proof.expectedCurrent) {
|
|
7026
7388
|
throw new UsageError("Admin API\u306Erollback\u7D50\u679C\u304C\u78BA\u8A8D\u6E08\u307F\u8A08\u753B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
7027
7389
|
}
|
|
@@ -7038,8 +7400,8 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
7038
7400
|
valid: true,
|
|
7039
7401
|
templateId: loaded.manifest.templateId,
|
|
7040
7402
|
templateVersion: loaded.manifest.version,
|
|
7041
|
-
templateCommitment: (0,
|
|
7042
|
-
bindingCommitment: (0,
|
|
7403
|
+
templateCommitment: (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest),
|
|
7404
|
+
bindingCommitment: (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings),
|
|
7043
7405
|
...loaded.exportApplicationCommitment ? { applicationCommitment: loaded.exportApplicationCommitment } : {}
|
|
7044
7406
|
});
|
|
7045
7407
|
});
|
|
@@ -7058,7 +7420,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
7058
7420
|
const projectId = assertProjectId(options.project);
|
|
7059
7421
|
const templateId = canonicalTemplateId(options.template);
|
|
7060
7422
|
const anchor = captureLocalRootPath(cwd());
|
|
7061
|
-
const result = (0,
|
|
7423
|
+
const result = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(
|
|
7062
7424
|
await runtime.createClient(options.profile).exportOnboardingTemplate(projectId, templateId)
|
|
7063
7425
|
);
|
|
7064
7426
|
if (result.projectId !== projectId || result.manifest.templateId !== templateId) {
|
|
@@ -7114,8 +7476,13 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
7114
7476
|
if (options.openapi !== void 0 && options.project === void 0) {
|
|
7115
7477
|
throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
|
|
7116
7478
|
}
|
|
7117
|
-
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
|
|
7118
|
-
throw new UsageError(
|
|
7479
|
+
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0 || options.authMode !== void 0 || (options.sideEffectFree?.length ?? 0) > 0)) {
|
|
7480
|
+
throw new UsageError(
|
|
7481
|
+
messages.optionRequires(
|
|
7482
|
+
"--base-url / --service-name / --auth-mode / --side-effect-free",
|
|
7483
|
+
"--openapi"
|
|
7484
|
+
)
|
|
7485
|
+
);
|
|
7119
7486
|
}
|
|
7120
7487
|
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)) {
|
|
7121
7488
|
throw new UsageError(
|
|
@@ -7140,26 +7507,36 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
7140
7507
|
}
|
|
7141
7508
|
}
|
|
7142
7509
|
async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
7143
|
-
if (options.openapi === void 0) return { options, anchor };
|
|
7510
|
+
if (options.openapi === void 0) return { options, anchor, notices: [] };
|
|
7511
|
+
const upstreamAuthMode = parseAuthModeOption(options.authMode);
|
|
7512
|
+
const sideEffectFree = parseSideEffectFreeOptions(options.sideEffectFree);
|
|
7144
7513
|
const contractPath = "tool-contract.json";
|
|
7145
7514
|
prepareLocalOrThrow(runtime, anchor, contractPath, messages);
|
|
7146
7515
|
const source = withAnchoredLocalRoot(
|
|
7147
7516
|
anchor.root,
|
|
7148
7517
|
anchor.rootIdentity,
|
|
7149
7518
|
() => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
|
|
7150
|
-
maxBytes:
|
|
7519
|
+
maxBytes: import_tool_contract8.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
7151
7520
|
root: anchor.root
|
|
7152
7521
|
})
|
|
7153
7522
|
);
|
|
7154
7523
|
let imported;
|
|
7155
7524
|
try {
|
|
7156
|
-
|
|
7525
|
+
const importOptions = {
|
|
7157
7526
|
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
7158
7527
|
...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
|
|
7159
|
-
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
|
|
7160
|
-
|
|
7528
|
+
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName },
|
|
7529
|
+
...upstreamAuthMode === void 0 ? {} : { upstreamAuthMode }
|
|
7530
|
+
};
|
|
7531
|
+
imported = (0, import_tool_contract8.importOpenApi)(source.text, importOptions);
|
|
7532
|
+
if (sideEffectFree.length > 0) {
|
|
7533
|
+
imported = (0, import_tool_contract8.importOpenApi)(source.text, {
|
|
7534
|
+
...importOptions,
|
|
7535
|
+
operationRiskOverrides: resolveOperationRiskOverrides(sideEffectFree, imported.operations)
|
|
7536
|
+
});
|
|
7537
|
+
}
|
|
7161
7538
|
} catch (error) {
|
|
7162
|
-
if (error instanceof
|
|
7539
|
+
if (error instanceof import_tool_contract8.OpenApiImportError) {
|
|
7163
7540
|
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
7164
7541
|
}
|
|
7165
7542
|
throw error;
|
|
@@ -7204,13 +7581,27 @@ async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
|
7204
7581
|
messages.failure("local_file_changed")
|
|
7205
7582
|
);
|
|
7206
7583
|
}
|
|
7584
|
+
const notices = [];
|
|
7585
|
+
if (upstreamAuthMode === void 0) {
|
|
7586
|
+
notices.push(
|
|
7587
|
+
"\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"
|
|
7588
|
+
);
|
|
7589
|
+
}
|
|
7590
|
+
const guidance = sideEffectFreeGuidance(imported.operations);
|
|
7591
|
+
if (guidance) {
|
|
7592
|
+
notices.push(
|
|
7593
|
+
`${guidance}
|
|
7594
|
+
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`
|
|
7595
|
+
);
|
|
7596
|
+
}
|
|
7207
7597
|
return {
|
|
7208
7598
|
options: {
|
|
7209
7599
|
project: options.project,
|
|
7210
7600
|
contract: contractPath,
|
|
7211
7601
|
profile: options.profile
|
|
7212
7602
|
},
|
|
7213
|
-
anchor: refreshedAnchor
|
|
7603
|
+
anchor: refreshedAnchor,
|
|
7604
|
+
notices
|
|
7214
7605
|
};
|
|
7215
7606
|
}
|
|
7216
7607
|
async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
@@ -7263,7 +7654,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7263
7654
|
contractPath,
|
|
7264
7655
|
anchor.root,
|
|
7265
7656
|
contractText,
|
|
7266
|
-
|
|
7657
|
+
import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7267
7658
|
{ expectedRootIdentity: anchor.rootIdentity }
|
|
7268
7659
|
);
|
|
7269
7660
|
} catch (error) {
|
|
@@ -7271,7 +7662,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7271
7662
|
try {
|
|
7272
7663
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template contract fallback");
|
|
7273
7664
|
const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
|
|
7274
|
-
maxBytes:
|
|
7665
|
+
maxBytes: import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7275
7666
|
root: anchor.root,
|
|
7276
7667
|
directChildOnly: true
|
|
7277
7668
|
});
|
|
@@ -7732,6 +8123,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7732
8123
|
const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
|
|
7733
8124
|
rootAnchor = materialized.anchor;
|
|
7734
8125
|
mode = normalizeInitOptions(materialized.options, messages);
|
|
8126
|
+
for (const notice of materialized.notices) interactive(writer, notice);
|
|
7735
8127
|
}
|
|
7736
8128
|
if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
|
|
7737
8129
|
let actionMode;
|
|
@@ -7807,7 +8199,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7807
8199
|
idempotencyKey: actionMode.connectorCreate.idempotencyKey,
|
|
7808
8200
|
connector: actionMode.connectorCreate.input
|
|
7809
8201
|
});
|
|
7810
|
-
if (created.projectId !== project.id || created.status !== "active" || created.name !== actionMode.connectorCreate.input.name || created.kind !== actionMode.connectorCreate.input.kind || created.upstreamAuthMode !== actionMode.connectorCreate.input.upstreamAuthMode || created.secretRef !== actionMode.connectorCreate.input.secretRef || created.config === null || (0,
|
|
8202
|
+
if (created.projectId !== project.id || created.status !== "active" || created.name !== actionMode.connectorCreate.input.name || created.kind !== actionMode.connectorCreate.input.kind || created.upstreamAuthMode !== actionMode.connectorCreate.input.upstreamAuthMode || created.secretRef !== actionMode.connectorCreate.input.secretRef || created.config === null || (0, import_tool_contract8.canonicalizePublicationJson)(created.config) !== (0, import_tool_contract8.canonicalizePublicationJson)(actionMode.connectorCreate.input.config)) {
|
|
7811
8203
|
throw new InitCommandError(
|
|
7812
8204
|
"AP_RESPONSE_INVALID",
|
|
7813
8205
|
"template_connector_create_mismatch",
|
|
@@ -7835,6 +8227,14 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7835
8227
|
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) {
|
|
7836
8228
|
const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
|
|
7837
8229
|
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(
|
|
8230
|
+
"--auth-mode <mode>",
|
|
8231
|
+
"OpenAPI upstream auth mode matching the publish connector: existing_oauth or token_exchange (default token_exchange)"
|
|
8232
|
+
).option(
|
|
8233
|
+
"--side-effect-free <toolName=level>",
|
|
8234
|
+
"Explicitly classify a POST that does not store, change or send data as read or draft (repeatable)",
|
|
8235
|
+
(value, previous) => [...previous, value],
|
|
8236
|
+
[]
|
|
8237
|
+
).option(
|
|
7838
8238
|
"--create-connector",
|
|
7839
8239
|
"Create the template connector through the existing Admin API policy boundary",
|
|
7840
8240
|
false
|
|
@@ -7942,6 +8342,14 @@ function buildInitTemplate(provider) {
|
|
|
7942
8342
|
scopes: ["openid", "profile"]
|
|
7943
8343
|
};
|
|
7944
8344
|
}
|
|
8345
|
+
function upstreamOAuthWizardUrl(profile, projectId, connectorId) {
|
|
8346
|
+
const record = getProfile(profile);
|
|
8347
|
+
if (!record)
|
|
8348
|
+
throw new UsageError(`\u8A8D\u8A3Cprofile ${profile} \u304C\u3042\u308A\u307E\u305B\u3093\u3002andpipe login\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044`);
|
|
8349
|
+
const url = new URL(`/projects/${projectId}/oauth`, new URL(record.verificationUriBase).origin);
|
|
8350
|
+
url.searchParams.set("connector", connectorId);
|
|
8351
|
+
return url.toString();
|
|
8352
|
+
}
|
|
7945
8353
|
async function loadOAuthMetadata(opts, locale) {
|
|
7946
8354
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7947
8355
|
if (opts.file && opts.issuer) {
|
|
@@ -7971,7 +8379,7 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
7971
8379
|
info(writer, messages.oauth.metadataOk);
|
|
7972
8380
|
}
|
|
7973
8381
|
}
|
|
7974
|
-
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8382
|
+
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE, dependencies = {}) {
|
|
7975
8383
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7976
8384
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
7977
8385
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
@@ -8052,6 +8460,43 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
8052
8460
|
metadata.command("validate").description(messages.oauth.validateDescription).option("--file <path>", messages.common.metadataFileOption).option("--issuer <url>", messages.common.issuerOption).action(async (opts) => {
|
|
8053
8461
|
await runOAuthMetadataValidate(opts, writer, locale);
|
|
8054
8462
|
});
|
|
8463
|
+
const connect = oauth.command("connect").description(
|
|
8464
|
+
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"
|
|
8465
|
+
);
|
|
8466
|
+
connect.command("status").description(
|
|
8467
|
+
locale === "ja" ? "\u63A5\u7D9A\u72B6\u614B\u3068\u6B21\u306E\u64CD\u4F5C\u3092\u8868\u793A" : "Show connection state and next action"
|
|
8468
|
+
).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) => {
|
|
8469
|
+
const state = await createAdminApiClient({
|
|
8470
|
+
profile: opts.profile
|
|
8471
|
+
}).getUpstreamOAuthConnectionState(assertProjectId(opts.project), opts.connector);
|
|
8472
|
+
json(writer, state);
|
|
8473
|
+
if (!state.allGreen) process.exitCode = 1;
|
|
8474
|
+
});
|
|
8475
|
+
connect.command("open").description(
|
|
8476
|
+
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"
|
|
8477
|
+
).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--connector <connector>", "\u63A5\u7D9A\u5BFE\u8C61connector UUID").option("--profile <name>", messages.common.targetProfileOption, DEFAULT_PROFILE_NAME).option(
|
|
8478
|
+
"--no-browser",
|
|
8479
|
+
locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u958B\u304B\u305AURL\u3060\u3051\u8868\u793A" : "Print the URL without opening a browser"
|
|
8480
|
+
).action(
|
|
8481
|
+
async (opts) => {
|
|
8482
|
+
const projectId = assertProjectId(opts.project);
|
|
8483
|
+
const state = await createAdminApiClient({
|
|
8484
|
+
profile: opts.profile
|
|
8485
|
+
}).getUpstreamOAuthConnectionState(projectId, opts.connector);
|
|
8486
|
+
json(writer, state);
|
|
8487
|
+
const url = upstreamOAuthWizardUrl(opts.profile, projectId, opts.connector);
|
|
8488
|
+
info(
|
|
8489
|
+
writer,
|
|
8490
|
+
locale === "ja" ? `Web Admin\u3067\u7D9A\u3051\u3066\u304F\u3060\u3055\u3044: ${url}` : `Continue in Web Admin: ${url}`
|
|
8491
|
+
);
|
|
8492
|
+
if (opts.browser) {
|
|
8493
|
+
try {
|
|
8494
|
+
(dependencies.openBrowser ?? openBrowser)(url);
|
|
8495
|
+
} catch {
|
|
8496
|
+
}
|
|
8497
|
+
}
|
|
8498
|
+
}
|
|
8499
|
+
);
|
|
8055
8500
|
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) => {
|
|
8056
8501
|
const projectId = assertProjectId(opts.project);
|
|
8057
8502
|
const result = await createAdminApiClient({ profile: opts.profile }).testOAuthLogin(
|
|
@@ -8066,7 +8511,7 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
8066
8511
|
// src/commands/openapi.ts
|
|
8067
8512
|
var import_node_crypto12 = require("crypto");
|
|
8068
8513
|
var import_node_path12 = require("path");
|
|
8069
|
-
var
|
|
8514
|
+
var import_tool_contract9 = require("@andpipes/tool-contract");
|
|
8070
8515
|
function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
8071
8516
|
return { createClient, idempotencyKey: import_node_crypto12.randomUUID };
|
|
8072
8517
|
}
|
|
@@ -8102,9 +8547,17 @@ function normalizedOptions(options) {
|
|
|
8102
8547
|
apply,
|
|
8103
8548
|
yes,
|
|
8104
8549
|
...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
|
|
8105
|
-
...options.planCommitment !== void 0 ? { planCommitment: options.planCommitment } : {}
|
|
8550
|
+
...options.planCommitment !== void 0 ? { planCommitment: options.planCommitment } : {},
|
|
8551
|
+
...options.authMode !== void 0 ? { upstreamAuthMode: parseAuthModeOption(options.authMode) } : {},
|
|
8552
|
+
sideEffectFree: parseSideEffectFreeOptions(options.sideEffectFree)
|
|
8106
8553
|
};
|
|
8107
8554
|
}
|
|
8555
|
+
function rethrowWithAuthModeGuidance(error) {
|
|
8556
|
+
if (error instanceof AdminApiClientError && error.openApiAuthModeMismatch) {
|
|
8557
|
+
throw new UsageError(authModeMismatchGuidance(error.openApiAuthModeMismatch));
|
|
8558
|
+
}
|
|
8559
|
+
throw error;
|
|
8560
|
+
}
|
|
8108
8561
|
async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
8109
8562
|
const normalized = normalizedOptions(options);
|
|
8110
8563
|
if (normalized.apply && !normalized.yes) {
|
|
@@ -8117,39 +8570,88 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
8117
8570
|
throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
|
|
8118
8571
|
}
|
|
8119
8572
|
const snapshot = readBoundedLocalFileSnapshot((0, import_node_path12.resolve)(cwd, normalized.file), {
|
|
8120
|
-
maxBytes:
|
|
8573
|
+
maxBytes: import_tool_contract9.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
8121
8574
|
root: cwd
|
|
8122
8575
|
});
|
|
8123
|
-
const
|
|
8576
|
+
const baseRequest = {
|
|
8124
8577
|
source: snapshot.text,
|
|
8125
8578
|
connectorId: normalized.connectorId,
|
|
8126
8579
|
...normalized.format !== void 0 ? { format: normalized.format } : {},
|
|
8127
8580
|
...normalized.baseUrl !== void 0 ? { baseUrl: normalized.baseUrl } : {},
|
|
8128
8581
|
...normalized.serviceName !== void 0 ? { serviceName: normalized.serviceName } : {},
|
|
8129
|
-
...normalized.
|
|
8582
|
+
...normalized.upstreamAuthMode !== void 0 ? { upstreamAuthMode: normalized.upstreamAuthMode } : {}
|
|
8130
8583
|
};
|
|
8131
8584
|
const client = runtime.createClient(normalized.profile);
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
if (result2.sourceCommitment !== snapshot.sha256) {
|
|
8585
|
+
const assertSource = (sourceCommitment) => {
|
|
8586
|
+
if (sourceCommitment !== snapshot.sha256) {
|
|
8135
8587
|
throw new UsageError("Admin API\u306Esource commitment\u304Clocal file\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
8136
8588
|
}
|
|
8137
|
-
|
|
8589
|
+
};
|
|
8590
|
+
let overrides = [];
|
|
8591
|
+
if (normalized.sideEffectFree.length > 0) {
|
|
8592
|
+
if (normalized.apply) {
|
|
8593
|
+
try {
|
|
8594
|
+
const unclassified = (0, import_tool_contract9.importOpenApi)(snapshot.text, {
|
|
8595
|
+
format: normalized.format,
|
|
8596
|
+
baseUrl: normalized.baseUrl,
|
|
8597
|
+
serviceName: normalized.serviceName,
|
|
8598
|
+
upstreamAuthMode: normalized.upstreamAuthMode
|
|
8599
|
+
});
|
|
8600
|
+
overrides = resolveOperationRiskOverrides(
|
|
8601
|
+
normalized.sideEffectFree,
|
|
8602
|
+
unclassified.operations
|
|
8603
|
+
);
|
|
8604
|
+
} catch (error) {
|
|
8605
|
+
if (error instanceof import_tool_contract9.OpenApiImportError) {
|
|
8606
|
+
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
8607
|
+
}
|
|
8608
|
+
throw error;
|
|
8609
|
+
}
|
|
8610
|
+
} else {
|
|
8611
|
+
const unclassified = await client.planOpenApiImport(normalized.project, baseRequest).catch(rethrowWithAuthModeGuidance);
|
|
8612
|
+
assertSource(unclassified.sourceCommitment);
|
|
8613
|
+
overrides = resolveOperationRiskOverrides(normalized.sideEffectFree, unclassified.operations);
|
|
8614
|
+
}
|
|
8615
|
+
}
|
|
8616
|
+
const request = {
|
|
8617
|
+
...baseRequest,
|
|
8618
|
+
...overrides.length > 0 ? { operationRiskOverrides: overrides } : {},
|
|
8619
|
+
...normalized.planCommitment !== void 0 ? { expectedPlanCommitment: normalized.planCommitment } : {}
|
|
8620
|
+
};
|
|
8621
|
+
const classification = {
|
|
8622
|
+
upstreamAuthMode: normalized.upstreamAuthMode ?? "token_exchange",
|
|
8623
|
+
operationRiskOverrides: overrides
|
|
8624
|
+
};
|
|
8625
|
+
if (!normalized.apply) {
|
|
8626
|
+
const result2 = await client.planOpenApiImport(normalized.project, request).catch(rethrowWithAuthModeGuidance);
|
|
8627
|
+
assertSource(result2.sourceCommitment);
|
|
8628
|
+
json(writer, { mode: "preview", ...classification, ...result2 });
|
|
8629
|
+
const guidance = sideEffectFreeGuidance(result2.operations);
|
|
8630
|
+
if (guidance) interactive(writer, guidance);
|
|
8138
8631
|
return;
|
|
8139
8632
|
}
|
|
8140
8633
|
const result = await client.applyOpenApiImport(
|
|
8141
8634
|
normalized.project,
|
|
8142
8635
|
normalized.idempotencyKey ?? runtime.idempotencyKey(),
|
|
8143
8636
|
request
|
|
8144
|
-
);
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8637
|
+
).catch(rethrowWithAuthModeGuidance);
|
|
8638
|
+
assertSource(result.sourceCommitment);
|
|
8639
|
+
json(writer, { mode: "draft_created", ...classification, ...result });
|
|
8640
|
+
}
|
|
8641
|
+
function collect(value, previous) {
|
|
8642
|
+
return [...previous, value];
|
|
8149
8643
|
}
|
|
8150
8644
|
function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
8151
8645
|
const openapi = program.command("openapi").description("OpenAPI\u304B\u3089Tool Contract draft\u3092\u63D0\u6848\u3059\u308B");
|
|
8152
|
-
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").
|
|
8646
|
+
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(
|
|
8647
|
+
"--auth-mode <mode>",
|
|
8648
|
+
"connector\u3068\u540C\u3058\u8A8D\u8A3C\u65B9\u5F0F\uFF08existing_oauth \u307E\u305F\u306F token_exchange\u3002\u7701\u7565\u6642\u306Ftoken_exchange\uFF09"
|
|
8649
|
+
).option(
|
|
8650
|
+
"--side-effect-free <toolName=level>",
|
|
8651
|
+
"\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",
|
|
8652
|
+
collect,
|
|
8653
|
+
[]
|
|
8654
|
+
).action(
|
|
8153
8655
|
(options) => runOpenApiImportCommand(options, writer, cwd(), runtime)
|
|
8154
8656
|
);
|
|
8155
8657
|
}
|
|
@@ -8157,7 +8659,7 @@ function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRunt
|
|
|
8157
8659
|
// src/commands/publish.ts
|
|
8158
8660
|
var import_node_crypto13 = require("crypto");
|
|
8159
8661
|
var import_localization10 = require("@andpipes/localization");
|
|
8160
|
-
var
|
|
8662
|
+
var import_tool_contract10 = require("@andpipes/tool-contract");
|
|
8161
8663
|
var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
8162
8664
|
var SAFE_AP_CODE_RE2 = /^AP_[A-Z0-9_]{1,64}$/u;
|
|
8163
8665
|
var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
@@ -8294,7 +8796,7 @@ function responseInvalid(reason, messages) {
|
|
|
8294
8796
|
}
|
|
8295
8797
|
function assertCanonicalResponseSize(value, reason, messages, maxBytes = PUBLICATION_RESPONSE_MAX_BYTES) {
|
|
8296
8798
|
try {
|
|
8297
|
-
(0,
|
|
8799
|
+
(0, import_tool_contract10.assertCanonicalPublicationSize)(value, maxBytes);
|
|
8298
8800
|
} catch {
|
|
8299
8801
|
throw responseInvalid(reason, messages);
|
|
8300
8802
|
}
|
|
@@ -8303,7 +8805,7 @@ function isCanonicalUuid(value) {
|
|
|
8303
8805
|
return typeof value === "string" && UUID_RE6.test(value);
|
|
8304
8806
|
}
|
|
8305
8807
|
function isCommitment(value) {
|
|
8306
|
-
return typeof value === "string" &&
|
|
8808
|
+
return typeof value === "string" && import_tool_contract10.PUBLICATION_SHA256_COMMITMENT_RE.test(value);
|
|
8307
8809
|
}
|
|
8308
8810
|
function isCanonicalTimestamp(value) {
|
|
8309
8811
|
if (typeof value !== "string" || value.length > 64) return false;
|
|
@@ -8312,12 +8814,12 @@ function isCanonicalTimestamp(value) {
|
|
|
8312
8814
|
}
|
|
8313
8815
|
function isStrictlySorted(values) {
|
|
8314
8816
|
return values.every(
|
|
8315
|
-
(value, index) => index === 0 || (0,
|
|
8817
|
+
(value, index) => index === 0 || (0, import_tool_contract10.comparePublicationUnicodeCodePoints)(values[index - 1], value) < 0
|
|
8316
8818
|
);
|
|
8317
8819
|
}
|
|
8318
8820
|
function parseWarnings(value, messages) {
|
|
8319
8821
|
try {
|
|
8320
|
-
return (0,
|
|
8822
|
+
return (0, import_tool_contract10.parsePublicationWarningsDto)(value);
|
|
8321
8823
|
} catch {
|
|
8322
8824
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8323
8825
|
}
|
|
@@ -8333,7 +8835,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8333
8835
|
const blockedReasons = plan.blockedReasons;
|
|
8334
8836
|
let safeDiff;
|
|
8335
8837
|
try {
|
|
8336
|
-
safeDiff = (0,
|
|
8838
|
+
safeDiff = (0, import_tool_contract10.parsePublicationSafeDiffDto)({
|
|
8337
8839
|
tools: plan.tools,
|
|
8338
8840
|
retainedTools: plan.retainedTools,
|
|
8339
8841
|
warnings: plan.warnings
|
|
@@ -8347,7 +8849,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8347
8849
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8348
8850
|
}
|
|
8349
8851
|
const warnings = safeDiff.warnings;
|
|
8350
|
-
const expectedPlanCommitment = (0,
|
|
8852
|
+
const expectedPlanCommitment = (0, import_tool_contract10.publicationCommitment)("plan", {
|
|
8351
8853
|
candidateCommitment,
|
|
8352
8854
|
baseCommitment: plan.baseCommitment,
|
|
8353
8855
|
connectorId,
|
|
@@ -8366,7 +8868,11 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8366
8868
|
}
|
|
8367
8869
|
const toolBlockedReasons = new Set(tools.flatMap((tool) => tool.blockedReasons));
|
|
8368
8870
|
if (tools.some((tool) => !tool.gate.ok) && plan.applyAllowed || tools.some((tool) => tool.opaqueChanged) && (plan.applyAllowed || !blockedReasons.includes("opaque_change")) || TOOL_BLOCKED_REASONS.some(
|
|
8369
|
-
(reason) =>
|
|
8871
|
+
(reason) => (
|
|
8872
|
+
// connector_mismatchはtool単位(既存toolの別connector束縛)に加え、candidateの
|
|
8873
|
+
// upstream.auth.modeとconnector方式の不一致としてtop-levelだけにも出る (#456 / #724)。
|
|
8874
|
+
reason === "connector_mismatch" ? toolBlockedReasons.has(reason) && !blockedReasons.includes(reason) : blockedReasons.includes(reason) !== toolBlockedReasons.has(reason)
|
|
8875
|
+
)
|
|
8370
8876
|
)) {
|
|
8371
8877
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8372
8878
|
}
|
|
@@ -8396,7 +8902,7 @@ function parseToolResults(value, messages) {
|
|
|
8396
8902
|
}
|
|
8397
8903
|
const tools = value.map((candidate) => {
|
|
8398
8904
|
const tool = asRecord4(candidate);
|
|
8399
|
-
if (!tool || !hasExactKeys3(tool, ["toolName", "operation", "toolId", "versionId", "version"]) || !(0,
|
|
8905
|
+
if (!tool || !hasExactKeys3(tool, ["toolName", "operation", "toolId", "versionId", "version"]) || !(0, import_tool_contract10.isSafeToolName)(tool.toolName) || tool.operation !== "create" && tool.operation !== "update" || !isCanonicalUuid(tool.toolId) || !isCanonicalUuid(tool.versionId) || typeof tool.version !== "number" || !Number.isSafeInteger(tool.version) || tool.version < 1) {
|
|
8400
8906
|
throw responseInvalid("publication_result_tool_invalid", messages);
|
|
8401
8907
|
}
|
|
8402
8908
|
const operation = tool.operation;
|
|
@@ -8453,7 +8959,7 @@ function parsePublicationResult(value, plan, messages, expectedPublicationId) {
|
|
|
8453
8959
|
function parseConfirmation(value, messages) {
|
|
8454
8960
|
if (value === null) return null;
|
|
8455
8961
|
const confirmation = asRecord4(value);
|
|
8456
|
-
if (!confirmation || !hasExactKeys3(confirmation, ["confirmationId", "signature", "confirmed"]) || !isCanonicalUuid(confirmation.confirmationId) || typeof confirmation.signature !== "string" || !
|
|
8962
|
+
if (!confirmation || !hasExactKeys3(confirmation, ["confirmationId", "signature", "confirmed"]) || !isCanonicalUuid(confirmation.confirmationId) || typeof confirmation.signature !== "string" || !import_tool_contract10.PUBLICATION_CONFIRMATION_SIGNATURE_RE.test(confirmation.signature) || confirmation.confirmed !== true) {
|
|
8457
8963
|
throw responseInvalid("publication_confirmation_invalid", messages);
|
|
8458
8964
|
}
|
|
8459
8965
|
return {
|
|
@@ -8576,11 +9082,11 @@ function freezeJson(value) {
|
|
|
8576
9082
|
return value;
|
|
8577
9083
|
}
|
|
8578
9084
|
function prepareCandidate(project) {
|
|
8579
|
-
const canonical = (0,
|
|
9085
|
+
const canonical = (0, import_tool_contract10.assertCanonicalPublicationSize)(project.contract.root);
|
|
8580
9086
|
const candidateContract = freezeJson(JSON.parse(canonical));
|
|
8581
9087
|
return {
|
|
8582
9088
|
candidateContract,
|
|
8583
|
-
candidateCommitment: (0,
|
|
9089
|
+
candidateCommitment: (0, import_tool_contract10.publicationCommitment)("candidate", candidateContract)
|
|
8584
9090
|
};
|
|
8585
9091
|
}
|
|
8586
9092
|
function assertIdempotencyKey2(value, messages) {
|
|
@@ -8784,15 +9290,15 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8784
9290
|
);
|
|
8785
9291
|
}
|
|
8786
9292
|
const candidate = prepareCandidate(project);
|
|
8787
|
-
const localToolNames = project.contract.tools.map((tool) => (0,
|
|
8788
|
-
if (localToolNames.some((name) => !(0,
|
|
9293
|
+
const localToolNames = project.contract.tools.map((tool) => (0, import_tool_contract10.toolName)(tool));
|
|
9294
|
+
if (localToolNames.some((name) => !(0, import_tool_contract10.isSafeToolName)(name))) {
|
|
8789
9295
|
throw new PublishCommandError(
|
|
8790
9296
|
"AP_INPUT_INVALID",
|
|
8791
9297
|
"publication_candidate_tool_invalid",
|
|
8792
9298
|
messages.failure("publication_candidate_tool_invalid")
|
|
8793
9299
|
);
|
|
8794
9300
|
}
|
|
8795
|
-
const expectedToolNames = localToolNames.sort(
|
|
9301
|
+
const expectedToolNames = localToolNames.sort(import_tool_contract10.comparePublicationUnicodeCodePoints);
|
|
8796
9302
|
const planRequest = {
|
|
8797
9303
|
environment: "production",
|
|
8798
9304
|
connectorId,
|
|
@@ -8820,6 +9326,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8820
9326
|
messages
|
|
8821
9327
|
);
|
|
8822
9328
|
writePlan(writer, plan);
|
|
9329
|
+
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
9330
|
+
interactive(writer, messages.connectorMismatchRemediation);
|
|
9331
|
+
}
|
|
8823
9332
|
if (normalized.mode === "dry-run") return;
|
|
8824
9333
|
if (!plan.applyAllowed) {
|
|
8825
9334
|
throw new PublishCommandError(
|