@andpipes/cli 0.1.1 → 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 +627 -74
- package/dist/bin.js +1 -1
- package/dist/{chunk-QPRR3KCS.js → chunk-6LTYTSZX.js} +595 -32
- package/dist/index.cjs +627 -74
- 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) {
|
|
@@ -3818,6 +4093,41 @@ async function loginAdminCli(input = {}) {
|
|
|
3818
4093
|
}
|
|
3819
4094
|
}
|
|
3820
4095
|
|
|
4096
|
+
// src/lib/open-browser.ts
|
|
4097
|
+
var import_node_child_process = require("child_process");
|
|
4098
|
+
function browserCommandForPlatform(verificationUri, platform = process.platform) {
|
|
4099
|
+
if (platform === "darwin") {
|
|
4100
|
+
return { command: "open", args: [verificationUri] };
|
|
4101
|
+
}
|
|
4102
|
+
if (platform === "win32") {
|
|
4103
|
+
return {
|
|
4104
|
+
command: "rundll32",
|
|
4105
|
+
args: ["url.dll,FileProtocolHandler", verificationUri]
|
|
4106
|
+
};
|
|
4107
|
+
}
|
|
4108
|
+
if (platform === "linux") {
|
|
4109
|
+
return { command: "xdg-open", args: [verificationUri] };
|
|
4110
|
+
}
|
|
4111
|
+
return null;
|
|
4112
|
+
}
|
|
4113
|
+
function openBrowser(verificationUri) {
|
|
4114
|
+
const browserCommand = browserCommandForPlatform(verificationUri);
|
|
4115
|
+
if (!browserCommand) return false;
|
|
4116
|
+
try {
|
|
4117
|
+
const child = (0, import_node_child_process.spawn)(browserCommand.command, [...browserCommand.args], {
|
|
4118
|
+
detached: true,
|
|
4119
|
+
shell: false,
|
|
4120
|
+
stdio: "ignore",
|
|
4121
|
+
windowsHide: true
|
|
4122
|
+
});
|
|
4123
|
+
child.once("error", () => void 0);
|
|
4124
|
+
child.unref();
|
|
4125
|
+
return true;
|
|
4126
|
+
} catch {
|
|
4127
|
+
return false;
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
|
|
3821
4131
|
// src/commands/auth.ts
|
|
3822
4132
|
function explicitScopes(value) {
|
|
3823
4133
|
if (value === void 0) return void 0;
|
|
@@ -3830,12 +4140,15 @@ function explicitScopes(value) {
|
|
|
3830
4140
|
}
|
|
3831
4141
|
return scopes;
|
|
3832
4142
|
}
|
|
3833
|
-
function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE) {
|
|
4143
|
+
function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE, dependencies = {}) {
|
|
3834
4144
|
const text = import_localization2.LOCALIZED_TEXT[locale].cli;
|
|
3835
4145
|
const messages = import_localization2.CLI_MESSAGES[locale];
|
|
3836
4146
|
program.command("login").description(
|
|
3837
4147
|
locale === "ja" ? "Web Admin\u627F\u8A8D\u3067Admin CLI\u3078\u30ED\u30B0\u30A4\u30F3" : "Sign in to the Admin CLI through Web Admin approval"
|
|
3838
|
-
).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).
|
|
4148
|
+
).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).option(
|
|
4149
|
+
"--no-browser",
|
|
4150
|
+
locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u81EA\u52D5\u8D77\u52D5\u305B\u305A\u3001\u627F\u8A8DURL\u3060\u3051\u3092\u8868\u793A" : "Print the approval URL without opening the default browser"
|
|
4151
|
+
).action(async (opts) => {
|
|
3839
4152
|
const record = await loginAdminCli({
|
|
3840
4153
|
profile: opts.profile,
|
|
3841
4154
|
requestedScopes: explicitScopes(opts.scope),
|
|
@@ -3844,6 +4157,12 @@ function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOC
|
|
|
3844
4157
|
writer,
|
|
3845
4158
|
locale === "ja" ? `Web Admin\u3067\u627F\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044: ${verificationUri}` : `Approve this request in Web Admin: ${verificationUri}`
|
|
3846
4159
|
);
|
|
4160
|
+
if (opts.browser) {
|
|
4161
|
+
try {
|
|
4162
|
+
(dependencies.openBrowser ?? openBrowser)(verificationUri);
|
|
4163
|
+
} catch {
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
3847
4166
|
},
|
|
3848
4167
|
onUserCode: (userCode) => {
|
|
3849
4168
|
interactive(
|
|
@@ -5554,7 +5873,7 @@ function loadDevProject(cwd, runtime = {}) {
|
|
|
5554
5873
|
}
|
|
5555
5874
|
|
|
5556
5875
|
// src/lib/dev-tunnel.ts
|
|
5557
|
-
var
|
|
5876
|
+
var import_node_child_process2 = require("child_process");
|
|
5558
5877
|
var import_node_fs7 = require("fs");
|
|
5559
5878
|
var import_node_path7 = require("path");
|
|
5560
5879
|
var QUICK_TUNNEL_PROVIDER = "cloudflare-quick";
|
|
@@ -5621,7 +5940,7 @@ async function terminateKnownProcessGroup(pgid, runtime = defaultProcessGroupRun
|
|
|
5621
5940
|
var defaultParentTunnelRuntime = {
|
|
5622
5941
|
...defaultProcessGroupRuntime,
|
|
5623
5942
|
forkSupervisor(modulePath, args, options) {
|
|
5624
|
-
return (0,
|
|
5943
|
+
return (0, import_node_child_process2.fork)(modulePath, [...args], {
|
|
5625
5944
|
detached: options.detached,
|
|
5626
5945
|
execArgv: [...options.execArgv],
|
|
5627
5946
|
stdio: [...options.stdio]
|
|
@@ -5715,7 +6034,7 @@ async function startCloudflareQuickTunnel(input, runtime = defaultParentTunnelRu
|
|
|
5715
6034
|
}
|
|
5716
6035
|
var defaultSupervisorRuntime = {
|
|
5717
6036
|
spawn(file, args, options) {
|
|
5718
|
-
return (0,
|
|
6037
|
+
return (0, import_node_child_process2.spawn)(file, [...args], {
|
|
5719
6038
|
shell: options.shell,
|
|
5720
6039
|
detached: options.detached,
|
|
5721
6040
|
stdio: [...options.stdio]
|
|
@@ -6191,7 +6510,7 @@ var import_node_crypto11 = require("crypto");
|
|
|
6191
6510
|
var import_node_path11 = require("path");
|
|
6192
6511
|
var import_promises2 = require("readline/promises");
|
|
6193
6512
|
var import_localization7 = require("@andpipes/localization");
|
|
6194
|
-
var
|
|
6513
|
+
var import_tool_contract8 = require("@andpipes/tool-contract");
|
|
6195
6514
|
|
|
6196
6515
|
// src/lib/init-manifest.ts
|
|
6197
6516
|
var import_node_fs10 = require("fs");
|
|
@@ -6714,6 +7033,93 @@ function writeInitManifestNoReplace(plan, manifest, runtime) {
|
|
|
6714
7033
|
});
|
|
6715
7034
|
}
|
|
6716
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
|
+
|
|
6717
7123
|
// src/lib/terminal-safe.ts
|
|
6718
7124
|
function isBidirectionalFormatControl(codePoint) {
|
|
6719
7125
|
return codePoint === 1564 || codePoint >= 8206 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
@@ -6750,7 +7156,7 @@ function terminalSafeValue(value) {
|
|
|
6750
7156
|
// src/commands/template.ts
|
|
6751
7157
|
var import_node_crypto10 = require("crypto");
|
|
6752
7158
|
var import_node_path10 = require("path");
|
|
6753
|
-
var
|
|
7159
|
+
var import_tool_contract7 = require("@andpipes/tool-contract");
|
|
6754
7160
|
var BINDINGS_MAX_BYTES = 64 * 1024;
|
|
6755
7161
|
var EXPORT_MAX_BYTES = 1280 * 1024;
|
|
6756
7162
|
var TEMPLATE_ID_RE2 = /^[a-z][a-z0-9._-]{0,63}$/u;
|
|
@@ -6758,7 +7164,7 @@ function createTemplateCommandRuntime(createClient = (profile) => createAdminApi
|
|
|
6758
7164
|
return { createClient, idempotencyKey: import_node_crypto10.randomUUID };
|
|
6759
7165
|
}
|
|
6760
7166
|
function jsonObject(text, label) {
|
|
6761
|
-
const parsed = (0,
|
|
7167
|
+
const parsed = (0, import_tool_contract7.parseToolContract)(text, { format: "json" });
|
|
6762
7168
|
if (!parsed.ok || !parsed.contract || typeof parsed.contract !== "object" || Array.isArray(parsed.contract)) {
|
|
6763
7169
|
throw new UsageError(`${label}\u306Fvalid JSON object\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
|
|
6764
7170
|
}
|
|
@@ -6785,7 +7191,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6785
7191
|
}
|
|
6786
7192
|
let exported;
|
|
6787
7193
|
try {
|
|
6788
|
-
exported = (0,
|
|
7194
|
+
exported = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(source);
|
|
6789
7195
|
} catch {
|
|
6790
7196
|
throw new UsageError("template export artifact\u306Eshape\u304C\u4E0D\u6B63\u3067\u3059");
|
|
6791
7197
|
}
|
|
@@ -6810,7 +7216,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6810
7216
|
}
|
|
6811
7217
|
const bindingSnapshot = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6812
7218
|
const bindingSource = jsonObject(bindingSnapshot.text, "bindings file");
|
|
6813
|
-
const manifest = (0,
|
|
7219
|
+
const manifest = (0, import_tool_contract7.parseExternalSaasTemplate)(source);
|
|
6814
7220
|
const verifiedTemplate = readArtifact(file, EXPORT_MAX_BYTES, "template file");
|
|
6815
7221
|
const verifiedBindings = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6816
7222
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template inputs final root");
|
|
@@ -6822,7 +7228,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6822
7228
|
}
|
|
6823
7229
|
return {
|
|
6824
7230
|
manifest,
|
|
6825
|
-
bindings: (0,
|
|
7231
|
+
bindings: (0, import_tool_contract7.parseOnboardingTemplateBindings)(manifest, bindingSource),
|
|
6826
7232
|
sourceSnapshot: { ...verifiedTemplate.identity, sha256: verifiedTemplate.sha256 }
|
|
6827
7233
|
};
|
|
6828
7234
|
} catch (error) {
|
|
@@ -6851,7 +7257,7 @@ function expectedCurrent(value) {
|
|
|
6851
7257
|
throw new UsageError("--apply\u306B\u306F--expected-current <commitment|none>\u304C\u5FC5\u9808\u3067\u3059");
|
|
6852
7258
|
}
|
|
6853
7259
|
if (value === "none") return null;
|
|
6854
|
-
if (!
|
|
7260
|
+
if (!import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(value)) {
|
|
6855
7261
|
throw new UsageError("--expected-current\u306Fsha256 commitment\u307E\u305F\u306Fnone\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
6856
7262
|
}
|
|
6857
7263
|
return value;
|
|
@@ -6871,7 +7277,7 @@ function applyProof(options) {
|
|
|
6871
7277
|
"\u5148\u306Bdry-run\u306Esafe diff\u3092\u78BA\u8A8D\u3057\u3001--apply --yes\u3067\u660E\u793A\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
6872
7278
|
);
|
|
6873
7279
|
}
|
|
6874
|
-
if (!options.planCommitment || !
|
|
7280
|
+
if (!options.planCommitment || !import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(options.planCommitment)) {
|
|
6875
7281
|
throw new UsageError("--apply\u306B\u306Fdry-run\u3067\u5F97\u305F--plan-commitment\u304C\u5FC5\u9808\u3067\u3059");
|
|
6876
7282
|
}
|
|
6877
7283
|
return {
|
|
@@ -6880,10 +7286,10 @@ function applyProof(options) {
|
|
|
6880
7286
|
};
|
|
6881
7287
|
}
|
|
6882
7288
|
function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
6883
|
-
const parsedPlan = (0,
|
|
6884
|
-
const templateCommitment = (0,
|
|
6885
|
-
const bindingCommitment = (0,
|
|
6886
|
-
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)({
|
|
6887
7293
|
projectId,
|
|
6888
7294
|
templateCommitment,
|
|
6889
7295
|
bindingCommitment
|
|
@@ -6893,10 +7299,10 @@ function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
|
6893
7299
|
}
|
|
6894
7300
|
}
|
|
6895
7301
|
function assertApplyMatchesLocal(result, projectId, loaded, planCommitment) {
|
|
6896
|
-
const parsed = (0,
|
|
6897
|
-
const templateCommitment = (0,
|
|
6898
|
-
const bindingCommitment = (0,
|
|
6899
|
-
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)({
|
|
6900
7306
|
projectId,
|
|
6901
7307
|
templateCommitment,
|
|
6902
7308
|
bindingCommitment
|
|
@@ -6946,7 +7352,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6946
7352
|
const client = runtime.createClient(options.profile ?? DEFAULT_PROFILE_NAME);
|
|
6947
7353
|
if (!proof) {
|
|
6948
7354
|
const plan = await client.planOnboardingTemplateRollback(projectId, templateId, targetRevision);
|
|
6949
|
-
const parsed2 = (0,
|
|
7355
|
+
const parsed2 = (0, import_tool_contract7.parseOnboardingTemplateSafePlanDto)(plan);
|
|
6950
7356
|
if (parsed2.projectId !== projectId || parsed2.templateId !== templateId || parsed2.operation !== "rollback" || parsed2.rollbackFromRevision !== targetRevision || parsed2.currentApplicationCommitment === null) {
|
|
6951
7357
|
throw new UsageError("Admin API\u306Erollback plan\u304C\u8981\u6C42scope\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6952
7358
|
}
|
|
@@ -6977,7 +7383,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6977
7383
|
confirmed: true
|
|
6978
7384
|
}
|
|
6979
7385
|
);
|
|
6980
|
-
const parsed = (0,
|
|
7386
|
+
const parsed = (0, import_tool_contract7.parseOnboardingTemplateApplyDto)(result);
|
|
6981
7387
|
if (parsed.projectId !== projectId || parsed.templateId !== templateId || parsed.operation !== "rollback" || parsed.rollbackFromRevision !== targetRevision || parsed.planCommitment !== proof.planCommitment || parsed.applicationCommitment === proof.expectedCurrent) {
|
|
6982
7388
|
throw new UsageError("Admin API\u306Erollback\u7D50\u679C\u304C\u78BA\u8A8D\u6E08\u307F\u8A08\u753B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6983
7389
|
}
|
|
@@ -6994,8 +7400,8 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
6994
7400
|
valid: true,
|
|
6995
7401
|
templateId: loaded.manifest.templateId,
|
|
6996
7402
|
templateVersion: loaded.manifest.version,
|
|
6997
|
-
templateCommitment: (0,
|
|
6998
|
-
bindingCommitment: (0,
|
|
7403
|
+
templateCommitment: (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest),
|
|
7404
|
+
bindingCommitment: (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings),
|
|
6999
7405
|
...loaded.exportApplicationCommitment ? { applicationCommitment: loaded.exportApplicationCommitment } : {}
|
|
7000
7406
|
});
|
|
7001
7407
|
});
|
|
@@ -7014,7 +7420,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
7014
7420
|
const projectId = assertProjectId(options.project);
|
|
7015
7421
|
const templateId = canonicalTemplateId(options.template);
|
|
7016
7422
|
const anchor = captureLocalRootPath(cwd());
|
|
7017
|
-
const result = (0,
|
|
7423
|
+
const result = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(
|
|
7018
7424
|
await runtime.createClient(options.profile).exportOnboardingTemplate(projectId, templateId)
|
|
7019
7425
|
);
|
|
7020
7426
|
if (result.projectId !== projectId || result.manifest.templateId !== templateId) {
|
|
@@ -7070,8 +7476,13 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
7070
7476
|
if (options.openapi !== void 0 && options.project === void 0) {
|
|
7071
7477
|
throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
|
|
7072
7478
|
}
|
|
7073
|
-
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
|
|
7074
|
-
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
|
+
);
|
|
7075
7486
|
}
|
|
7076
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)) {
|
|
7077
7488
|
throw new UsageError(
|
|
@@ -7096,26 +7507,36 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
7096
7507
|
}
|
|
7097
7508
|
}
|
|
7098
7509
|
async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
7099
|
-
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);
|
|
7100
7513
|
const contractPath = "tool-contract.json";
|
|
7101
7514
|
prepareLocalOrThrow(runtime, anchor, contractPath, messages);
|
|
7102
7515
|
const source = withAnchoredLocalRoot(
|
|
7103
7516
|
anchor.root,
|
|
7104
7517
|
anchor.rootIdentity,
|
|
7105
7518
|
() => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
|
|
7106
|
-
maxBytes:
|
|
7519
|
+
maxBytes: import_tool_contract8.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
7107
7520
|
root: anchor.root
|
|
7108
7521
|
})
|
|
7109
7522
|
);
|
|
7110
7523
|
let imported;
|
|
7111
7524
|
try {
|
|
7112
|
-
|
|
7525
|
+
const importOptions = {
|
|
7113
7526
|
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
7114
7527
|
...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
|
|
7115
|
-
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
|
|
7116
|
-
|
|
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
|
+
}
|
|
7117
7538
|
} catch (error) {
|
|
7118
|
-
if (error instanceof
|
|
7539
|
+
if (error instanceof import_tool_contract8.OpenApiImportError) {
|
|
7119
7540
|
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
7120
7541
|
}
|
|
7121
7542
|
throw error;
|
|
@@ -7160,13 +7581,27 @@ async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
|
7160
7581
|
messages.failure("local_file_changed")
|
|
7161
7582
|
);
|
|
7162
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
|
+
}
|
|
7163
7597
|
return {
|
|
7164
7598
|
options: {
|
|
7165
7599
|
project: options.project,
|
|
7166
7600
|
contract: contractPath,
|
|
7167
7601
|
profile: options.profile
|
|
7168
7602
|
},
|
|
7169
|
-
anchor: refreshedAnchor
|
|
7603
|
+
anchor: refreshedAnchor,
|
|
7604
|
+
notices
|
|
7170
7605
|
};
|
|
7171
7606
|
}
|
|
7172
7607
|
async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
@@ -7219,7 +7654,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7219
7654
|
contractPath,
|
|
7220
7655
|
anchor.root,
|
|
7221
7656
|
contractText,
|
|
7222
|
-
|
|
7657
|
+
import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7223
7658
|
{ expectedRootIdentity: anchor.rootIdentity }
|
|
7224
7659
|
);
|
|
7225
7660
|
} catch (error) {
|
|
@@ -7227,7 +7662,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7227
7662
|
try {
|
|
7228
7663
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template contract fallback");
|
|
7229
7664
|
const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
|
|
7230
|
-
maxBytes:
|
|
7665
|
+
maxBytes: import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7231
7666
|
root: anchor.root,
|
|
7232
7667
|
directChildOnly: true
|
|
7233
7668
|
});
|
|
@@ -7688,6 +8123,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7688
8123
|
const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
|
|
7689
8124
|
rootAnchor = materialized.anchor;
|
|
7690
8125
|
mode = normalizeInitOptions(materialized.options, messages);
|
|
8126
|
+
for (const notice of materialized.notices) interactive(writer, notice);
|
|
7691
8127
|
}
|
|
7692
8128
|
if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
|
|
7693
8129
|
let actionMode;
|
|
@@ -7763,7 +8199,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7763
8199
|
idempotencyKey: actionMode.connectorCreate.idempotencyKey,
|
|
7764
8200
|
connector: actionMode.connectorCreate.input
|
|
7765
8201
|
});
|
|
7766
|
-
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)) {
|
|
7767
8203
|
throw new InitCommandError(
|
|
7768
8204
|
"AP_RESPONSE_INVALID",
|
|
7769
8205
|
"template_connector_create_mismatch",
|
|
@@ -7791,6 +8227,14 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7791
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) {
|
|
7792
8228
|
const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
|
|
7793
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(
|
|
7794
8238
|
"--create-connector",
|
|
7795
8239
|
"Create the template connector through the existing Admin API policy boundary",
|
|
7796
8240
|
false
|
|
@@ -7898,6 +8342,14 @@ function buildInitTemplate(provider) {
|
|
|
7898
8342
|
scopes: ["openid", "profile"]
|
|
7899
8343
|
};
|
|
7900
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
|
+
}
|
|
7901
8353
|
async function loadOAuthMetadata(opts, locale) {
|
|
7902
8354
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7903
8355
|
if (opts.file && opts.issuer) {
|
|
@@ -7927,7 +8379,7 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
7927
8379
|
info(writer, messages.oauth.metadataOk);
|
|
7928
8380
|
}
|
|
7929
8381
|
}
|
|
7930
|
-
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8382
|
+
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE, dependencies = {}) {
|
|
7931
8383
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7932
8384
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
7933
8385
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
@@ -8008,6 +8460,43 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
8008
8460
|
metadata.command("validate").description(messages.oauth.validateDescription).option("--file <path>", messages.common.metadataFileOption).option("--issuer <url>", messages.common.issuerOption).action(async (opts) => {
|
|
8009
8461
|
await runOAuthMetadataValidate(opts, writer, locale);
|
|
8010
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
|
+
);
|
|
8011
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) => {
|
|
8012
8501
|
const projectId = assertProjectId(opts.project);
|
|
8013
8502
|
const result = await createAdminApiClient({ profile: opts.profile }).testOAuthLogin(
|
|
@@ -8022,7 +8511,7 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
8022
8511
|
// src/commands/openapi.ts
|
|
8023
8512
|
var import_node_crypto12 = require("crypto");
|
|
8024
8513
|
var import_node_path12 = require("path");
|
|
8025
|
-
var
|
|
8514
|
+
var import_tool_contract9 = require("@andpipes/tool-contract");
|
|
8026
8515
|
function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
8027
8516
|
return { createClient, idempotencyKey: import_node_crypto12.randomUUID };
|
|
8028
8517
|
}
|
|
@@ -8058,9 +8547,17 @@ function normalizedOptions(options) {
|
|
|
8058
8547
|
apply,
|
|
8059
8548
|
yes,
|
|
8060
8549
|
...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
|
|
8061
|
-
...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)
|
|
8062
8553
|
};
|
|
8063
8554
|
}
|
|
8555
|
+
function rethrowWithAuthModeGuidance(error) {
|
|
8556
|
+
if (error instanceof AdminApiClientError && error.openApiAuthModeMismatch) {
|
|
8557
|
+
throw new UsageError(authModeMismatchGuidance(error.openApiAuthModeMismatch));
|
|
8558
|
+
}
|
|
8559
|
+
throw error;
|
|
8560
|
+
}
|
|
8064
8561
|
async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
8065
8562
|
const normalized = normalizedOptions(options);
|
|
8066
8563
|
if (normalized.apply && !normalized.yes) {
|
|
@@ -8073,39 +8570,88 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
8073
8570
|
throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
|
|
8074
8571
|
}
|
|
8075
8572
|
const snapshot = readBoundedLocalFileSnapshot((0, import_node_path12.resolve)(cwd, normalized.file), {
|
|
8076
|
-
maxBytes:
|
|
8573
|
+
maxBytes: import_tool_contract9.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
8077
8574
|
root: cwd
|
|
8078
8575
|
});
|
|
8079
|
-
const
|
|
8576
|
+
const baseRequest = {
|
|
8080
8577
|
source: snapshot.text,
|
|
8081
8578
|
connectorId: normalized.connectorId,
|
|
8082
8579
|
...normalized.format !== void 0 ? { format: normalized.format } : {},
|
|
8083
8580
|
...normalized.baseUrl !== void 0 ? { baseUrl: normalized.baseUrl } : {},
|
|
8084
8581
|
...normalized.serviceName !== void 0 ? { serviceName: normalized.serviceName } : {},
|
|
8085
|
-
...normalized.
|
|
8582
|
+
...normalized.upstreamAuthMode !== void 0 ? { upstreamAuthMode: normalized.upstreamAuthMode } : {}
|
|
8086
8583
|
};
|
|
8087
8584
|
const client = runtime.createClient(normalized.profile);
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
if (result2.sourceCommitment !== snapshot.sha256) {
|
|
8585
|
+
const assertSource = (sourceCommitment) => {
|
|
8586
|
+
if (sourceCommitment !== snapshot.sha256) {
|
|
8091
8587
|
throw new UsageError("Admin API\u306Esource commitment\u304Clocal file\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
8092
8588
|
}
|
|
8093
|
-
|
|
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);
|
|
8094
8631
|
return;
|
|
8095
8632
|
}
|
|
8096
8633
|
const result = await client.applyOpenApiImport(
|
|
8097
8634
|
normalized.project,
|
|
8098
8635
|
normalized.idempotencyKey ?? runtime.idempotencyKey(),
|
|
8099
8636
|
request
|
|
8100
|
-
);
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
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];
|
|
8105
8643
|
}
|
|
8106
8644
|
function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
8107
8645
|
const openapi = program.command("openapi").description("OpenAPI\u304B\u3089Tool Contract draft\u3092\u63D0\u6848\u3059\u308B");
|
|
8108
|
-
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(
|
|
8109
8655
|
(options) => runOpenApiImportCommand(options, writer, cwd(), runtime)
|
|
8110
8656
|
);
|
|
8111
8657
|
}
|
|
@@ -8113,7 +8659,7 @@ function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRunt
|
|
|
8113
8659
|
// src/commands/publish.ts
|
|
8114
8660
|
var import_node_crypto13 = require("crypto");
|
|
8115
8661
|
var import_localization10 = require("@andpipes/localization");
|
|
8116
|
-
var
|
|
8662
|
+
var import_tool_contract10 = require("@andpipes/tool-contract");
|
|
8117
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;
|
|
8118
8664
|
var SAFE_AP_CODE_RE2 = /^AP_[A-Z0-9_]{1,64}$/u;
|
|
8119
8665
|
var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
@@ -8250,7 +8796,7 @@ function responseInvalid(reason, messages) {
|
|
|
8250
8796
|
}
|
|
8251
8797
|
function assertCanonicalResponseSize(value, reason, messages, maxBytes = PUBLICATION_RESPONSE_MAX_BYTES) {
|
|
8252
8798
|
try {
|
|
8253
|
-
(0,
|
|
8799
|
+
(0, import_tool_contract10.assertCanonicalPublicationSize)(value, maxBytes);
|
|
8254
8800
|
} catch {
|
|
8255
8801
|
throw responseInvalid(reason, messages);
|
|
8256
8802
|
}
|
|
@@ -8259,7 +8805,7 @@ function isCanonicalUuid(value) {
|
|
|
8259
8805
|
return typeof value === "string" && UUID_RE6.test(value);
|
|
8260
8806
|
}
|
|
8261
8807
|
function isCommitment(value) {
|
|
8262
|
-
return typeof value === "string" &&
|
|
8808
|
+
return typeof value === "string" && import_tool_contract10.PUBLICATION_SHA256_COMMITMENT_RE.test(value);
|
|
8263
8809
|
}
|
|
8264
8810
|
function isCanonicalTimestamp(value) {
|
|
8265
8811
|
if (typeof value !== "string" || value.length > 64) return false;
|
|
@@ -8268,12 +8814,12 @@ function isCanonicalTimestamp(value) {
|
|
|
8268
8814
|
}
|
|
8269
8815
|
function isStrictlySorted(values) {
|
|
8270
8816
|
return values.every(
|
|
8271
|
-
(value, index) => index === 0 || (0,
|
|
8817
|
+
(value, index) => index === 0 || (0, import_tool_contract10.comparePublicationUnicodeCodePoints)(values[index - 1], value) < 0
|
|
8272
8818
|
);
|
|
8273
8819
|
}
|
|
8274
8820
|
function parseWarnings(value, messages) {
|
|
8275
8821
|
try {
|
|
8276
|
-
return (0,
|
|
8822
|
+
return (0, import_tool_contract10.parsePublicationWarningsDto)(value);
|
|
8277
8823
|
} catch {
|
|
8278
8824
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8279
8825
|
}
|
|
@@ -8289,7 +8835,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8289
8835
|
const blockedReasons = plan.blockedReasons;
|
|
8290
8836
|
let safeDiff;
|
|
8291
8837
|
try {
|
|
8292
|
-
safeDiff = (0,
|
|
8838
|
+
safeDiff = (0, import_tool_contract10.parsePublicationSafeDiffDto)({
|
|
8293
8839
|
tools: plan.tools,
|
|
8294
8840
|
retainedTools: plan.retainedTools,
|
|
8295
8841
|
warnings: plan.warnings
|
|
@@ -8303,7 +8849,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8303
8849
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8304
8850
|
}
|
|
8305
8851
|
const warnings = safeDiff.warnings;
|
|
8306
|
-
const expectedPlanCommitment = (0,
|
|
8852
|
+
const expectedPlanCommitment = (0, import_tool_contract10.publicationCommitment)("plan", {
|
|
8307
8853
|
candidateCommitment,
|
|
8308
8854
|
baseCommitment: plan.baseCommitment,
|
|
8309
8855
|
connectorId,
|
|
@@ -8322,7 +8868,11 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8322
8868
|
}
|
|
8323
8869
|
const toolBlockedReasons = new Set(tools.flatMap((tool) => tool.blockedReasons));
|
|
8324
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(
|
|
8325
|
-
(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
|
+
)
|
|
8326
8876
|
)) {
|
|
8327
8877
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8328
8878
|
}
|
|
@@ -8352,7 +8902,7 @@ function parseToolResults(value, messages) {
|
|
|
8352
8902
|
}
|
|
8353
8903
|
const tools = value.map((candidate) => {
|
|
8354
8904
|
const tool = asRecord4(candidate);
|
|
8355
|
-
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) {
|
|
8356
8906
|
throw responseInvalid("publication_result_tool_invalid", messages);
|
|
8357
8907
|
}
|
|
8358
8908
|
const operation = tool.operation;
|
|
@@ -8409,7 +8959,7 @@ function parsePublicationResult(value, plan, messages, expectedPublicationId) {
|
|
|
8409
8959
|
function parseConfirmation(value, messages) {
|
|
8410
8960
|
if (value === null) return null;
|
|
8411
8961
|
const confirmation = asRecord4(value);
|
|
8412
|
-
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) {
|
|
8413
8963
|
throw responseInvalid("publication_confirmation_invalid", messages);
|
|
8414
8964
|
}
|
|
8415
8965
|
return {
|
|
@@ -8532,11 +9082,11 @@ function freezeJson(value) {
|
|
|
8532
9082
|
return value;
|
|
8533
9083
|
}
|
|
8534
9084
|
function prepareCandidate(project) {
|
|
8535
|
-
const canonical = (0,
|
|
9085
|
+
const canonical = (0, import_tool_contract10.assertCanonicalPublicationSize)(project.contract.root);
|
|
8536
9086
|
const candidateContract = freezeJson(JSON.parse(canonical));
|
|
8537
9087
|
return {
|
|
8538
9088
|
candidateContract,
|
|
8539
|
-
candidateCommitment: (0,
|
|
9089
|
+
candidateCommitment: (0, import_tool_contract10.publicationCommitment)("candidate", candidateContract)
|
|
8540
9090
|
};
|
|
8541
9091
|
}
|
|
8542
9092
|
function assertIdempotencyKey2(value, messages) {
|
|
@@ -8740,15 +9290,15 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8740
9290
|
);
|
|
8741
9291
|
}
|
|
8742
9292
|
const candidate = prepareCandidate(project);
|
|
8743
|
-
const localToolNames = project.contract.tools.map((tool) => (0,
|
|
8744
|
-
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))) {
|
|
8745
9295
|
throw new PublishCommandError(
|
|
8746
9296
|
"AP_INPUT_INVALID",
|
|
8747
9297
|
"publication_candidate_tool_invalid",
|
|
8748
9298
|
messages.failure("publication_candidate_tool_invalid")
|
|
8749
9299
|
);
|
|
8750
9300
|
}
|
|
8751
|
-
const expectedToolNames = localToolNames.sort(
|
|
9301
|
+
const expectedToolNames = localToolNames.sort(import_tool_contract10.comparePublicationUnicodeCodePoints);
|
|
8752
9302
|
const planRequest = {
|
|
8753
9303
|
environment: "production",
|
|
8754
9304
|
connectorId,
|
|
@@ -8776,6 +9326,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8776
9326
|
messages
|
|
8777
9327
|
);
|
|
8778
9328
|
writePlan(writer, plan);
|
|
9329
|
+
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
9330
|
+
interactive(writer, messages.connectorMismatchRemediation);
|
|
9331
|
+
}
|
|
8779
9332
|
if (normalized.mode === "dry-run") return;
|
|
8780
9333
|
if (!plan.applyAllowed) {
|
|
8781
9334
|
throw new PublishCommandError(
|