@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/bin.cjs
CHANGED
|
@@ -489,12 +489,14 @@ var AdminApiClientError = class extends Error {
|
|
|
489
489
|
code;
|
|
490
490
|
status;
|
|
491
491
|
confirmationRequired;
|
|
492
|
-
|
|
492
|
+
openApiAuthModeMismatch;
|
|
493
|
+
constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch) {
|
|
493
494
|
super(message);
|
|
494
495
|
this.name = "AdminApiClientError";
|
|
495
496
|
this.code = code;
|
|
496
497
|
this.status = status;
|
|
497
498
|
this.confirmationRequired = confirmationRequired;
|
|
499
|
+
this.openApiAuthModeMismatch = openApiAuthModeMismatch;
|
|
498
500
|
}
|
|
499
501
|
};
|
|
500
502
|
function clientError(code, message, status) {
|
|
@@ -704,9 +706,27 @@ function withKnownResponseStatus(error, responseStatus) {
|
|
|
704
706
|
error.code,
|
|
705
707
|
error.message,
|
|
706
708
|
responseStatus,
|
|
707
|
-
error.confirmationRequired
|
|
709
|
+
error.confirmationRequired,
|
|
710
|
+
error.openApiAuthModeMismatch
|
|
708
711
|
);
|
|
709
712
|
}
|
|
713
|
+
var CONNECTOR_AUTH_MODES = /* @__PURE__ */ new Set([
|
|
714
|
+
"token_exchange",
|
|
715
|
+
"service_account",
|
|
716
|
+
"existing_oauth",
|
|
717
|
+
"signed_request"
|
|
718
|
+
]);
|
|
719
|
+
function parseOpenApiImportAuthModeMismatch(value) {
|
|
720
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
721
|
+
const details = value;
|
|
722
|
+
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) {
|
|
723
|
+
return void 0;
|
|
724
|
+
}
|
|
725
|
+
return {
|
|
726
|
+
connectorAuthMode: details.connectorAuthMode,
|
|
727
|
+
requestedAuthMode: details.requestedAuthMode
|
|
728
|
+
};
|
|
729
|
+
}
|
|
710
730
|
function unicodeScalarLength(value) {
|
|
711
731
|
let length = 0;
|
|
712
732
|
for (const character of value) {
|
|
@@ -733,11 +753,13 @@ function safeApiError(status, value) {
|
|
|
733
753
|
const candidate = errorRecord?.code;
|
|
734
754
|
const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
|
|
735
755
|
const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
|
|
756
|
+
const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
|
|
736
757
|
return new AdminApiClientError(
|
|
737
758
|
code,
|
|
738
759
|
`Admin API request failed (${code}; HTTP ${status})`,
|
|
739
760
|
status,
|
|
740
|
-
confirmationRequired
|
|
761
|
+
confirmationRequired,
|
|
762
|
+
openApiAuthModeMismatch
|
|
741
763
|
);
|
|
742
764
|
}
|
|
743
765
|
function buildUrl(path) {
|
|
@@ -890,16 +912,38 @@ function publicationApplyBody(input) {
|
|
|
890
912
|
};
|
|
891
913
|
}
|
|
892
914
|
function openApiImportBody(input) {
|
|
893
|
-
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)) {
|
|
915
|
+
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)) {
|
|
894
916
|
throw clientError("AP_INPUT_INVALID", "OpenAPI import request is invalid");
|
|
895
917
|
}
|
|
918
|
+
let operationRiskOverrides;
|
|
919
|
+
if (input.operationRiskOverrides !== void 0) {
|
|
920
|
+
try {
|
|
921
|
+
operationRiskOverrides = (0, import_tool_contract.parseOpenApiImportOperationRiskOverrides)(
|
|
922
|
+
input.operationRiskOverrides
|
|
923
|
+
);
|
|
924
|
+
} catch (error) {
|
|
925
|
+
if (error instanceof import_tool_contract.OpenApiImportError) {
|
|
926
|
+
throw clientError("AP_INPUT_INVALID", "OpenAPI import request is invalid");
|
|
927
|
+
}
|
|
928
|
+
throw error;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
896
931
|
return {
|
|
897
932
|
source: input.source,
|
|
898
933
|
connectorId: input.connectorId,
|
|
899
934
|
...input.expectedPlanCommitment !== void 0 ? { expectedPlanCommitment: input.expectedPlanCommitment } : {},
|
|
900
935
|
...input.format !== void 0 ? { format: input.format } : {},
|
|
901
936
|
...input.baseUrl !== void 0 ? { baseUrl: input.baseUrl } : {},
|
|
902
|
-
...input.serviceName !== void 0 ? { serviceName: input.serviceName } : {}
|
|
937
|
+
...input.serviceName !== void 0 ? { serviceName: input.serviceName } : {},
|
|
938
|
+
...input.upstreamAuthMode !== void 0 ? { upstreamAuthMode: input.upstreamAuthMode } : {},
|
|
939
|
+
...operationRiskOverrides !== void 0 ? {
|
|
940
|
+
operationRiskOverrides: operationRiskOverrides.map((override) => ({
|
|
941
|
+
toolName: override.toolName,
|
|
942
|
+
method: override.method,
|
|
943
|
+
path: override.path,
|
|
944
|
+
riskLevel: override.riskLevel
|
|
945
|
+
}))
|
|
946
|
+
} : {}
|
|
903
947
|
};
|
|
904
948
|
}
|
|
905
949
|
function parseSafeGateIssues(value, label) {
|
|
@@ -1575,6 +1619,15 @@ var AdminApiClient = class {
|
|
|
1575
1619
|
alignment: parseOAuthAlignmentSummary(value.alignment)
|
|
1576
1620
|
};
|
|
1577
1621
|
}
|
|
1622
|
+
async getUpstreamOAuthConnectionState(projectId, connectorId) {
|
|
1623
|
+
const project = assertProjectId(projectId);
|
|
1624
|
+
const connector = assertResourceId(connectorId, "--connector");
|
|
1625
|
+
return parseUpstreamOAuthConnectionState(
|
|
1626
|
+
await this.#request(
|
|
1627
|
+
`/v1/projects/${project}/connectors/${encodeURIComponent(connector)}/oauth-connection-state`
|
|
1628
|
+
)
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1578
1631
|
async syncOAuthScopes(input) {
|
|
1579
1632
|
const value = asObject(
|
|
1580
1633
|
await this.#request(`/v1/projects/${assertProjectId(input.projectId)}/oauth/scopes:sync`, {
|
|
@@ -2262,6 +2315,228 @@ function parseOAuthAlignmentSummary(value) {
|
|
|
2262
2315
|
)
|
|
2263
2316
|
};
|
|
2264
2317
|
}
|
|
2318
|
+
function parseUpstreamOAuthConnectionState(value) {
|
|
2319
|
+
const label = "upstream OAuth connection state";
|
|
2320
|
+
const state = asObject(value, label);
|
|
2321
|
+
exactKeys(
|
|
2322
|
+
state,
|
|
2323
|
+
[
|
|
2324
|
+
"connectorId",
|
|
2325
|
+
"profile",
|
|
2326
|
+
"secretPresence",
|
|
2327
|
+
"links",
|
|
2328
|
+
"selectedLinkId",
|
|
2329
|
+
"mcpResource",
|
|
2330
|
+
"smokeTools",
|
|
2331
|
+
"requiredScopes",
|
|
2332
|
+
"scopes",
|
|
2333
|
+
"redirectUri",
|
|
2334
|
+
"diagnostics",
|
|
2335
|
+
"allGreen",
|
|
2336
|
+
"currentStep",
|
|
2337
|
+
"nextAction"
|
|
2338
|
+
],
|
|
2339
|
+
label
|
|
2340
|
+
);
|
|
2341
|
+
const newFields = ["selectedLinkId", "mcpResource", "smokeTools"];
|
|
2342
|
+
if (newFields.some((key) => Object.hasOwn(state, key)) && !newFields.every((key) => Object.hasOwn(state, key))) {
|
|
2343
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label} has incomplete fields`);
|
|
2344
|
+
}
|
|
2345
|
+
const connectorId = assertUuid(state.connectorId, `${label}.connectorId`);
|
|
2346
|
+
if (state.secretPresence !== "configured" && state.secretPresence !== "not_configured") {
|
|
2347
|
+
throw clientError(
|
|
2348
|
+
"AP_RESPONSE_INVALID",
|
|
2349
|
+
`Admin API response ${label}.secretPresence is invalid`
|
|
2350
|
+
);
|
|
2351
|
+
}
|
|
2352
|
+
let issuer = null;
|
|
2353
|
+
if (state.profile !== null) {
|
|
2354
|
+
const profile = asObject(state.profile, `${label}.profile`);
|
|
2355
|
+
exactKeys(
|
|
2356
|
+
profile,
|
|
2357
|
+
[
|
|
2358
|
+
"connectorId",
|
|
2359
|
+
"issuer",
|
|
2360
|
+
"authorizationEndpoint",
|
|
2361
|
+
"tokenEndpoint",
|
|
2362
|
+
"jwksUri",
|
|
2363
|
+
"introspectionEndpoint",
|
|
2364
|
+
"revocationEndpoint",
|
|
2365
|
+
"upstreamResource",
|
|
2366
|
+
"clientId",
|
|
2367
|
+
"allowedScopes",
|
|
2368
|
+
"generation",
|
|
2369
|
+
"status",
|
|
2370
|
+
"updatedAt"
|
|
2371
|
+
],
|
|
2372
|
+
`${label}.profile`
|
|
2373
|
+
);
|
|
2374
|
+
if (assertUuid(profile.connectorId, `${label}.profile.connectorId`) !== connectorId) {
|
|
2375
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.profile is unbound`);
|
|
2376
|
+
}
|
|
2377
|
+
issuer = stringField(profile, "issuer", `${label}.profile`);
|
|
2378
|
+
stringArrayField(profile, "allowedScopes", `${label}.profile`);
|
|
2379
|
+
}
|
|
2380
|
+
if (!Array.isArray(state.links)) {
|
|
2381
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.links is invalid`);
|
|
2382
|
+
}
|
|
2383
|
+
const hasSelection = Object.hasOwn(state, "selectedLinkId");
|
|
2384
|
+
const selectedLinkId = hasSelection ? nullableUuidField(state, "selectedLinkId", label) : null;
|
|
2385
|
+
let activeLink = false;
|
|
2386
|
+
let grantedScopes = [];
|
|
2387
|
+
let activeCount = 0;
|
|
2388
|
+
let selectedCount = 0;
|
|
2389
|
+
const linkIds = /* @__PURE__ */ new Set();
|
|
2390
|
+
for (const [index, entry] of state.links.entries()) {
|
|
2391
|
+
const linkLabel = `${label}.links[${index}]`;
|
|
2392
|
+
const link2 = asObject(entry, linkLabel);
|
|
2393
|
+
exactKeys(
|
|
2394
|
+
link2,
|
|
2395
|
+
[
|
|
2396
|
+
"id",
|
|
2397
|
+
"connectorId",
|
|
2398
|
+
"status",
|
|
2399
|
+
"grantedScopes",
|
|
2400
|
+
"accessExpiresAt",
|
|
2401
|
+
"refreshGeneration",
|
|
2402
|
+
"linkedAt",
|
|
2403
|
+
"refreshedAt",
|
|
2404
|
+
"revokedAt"
|
|
2405
|
+
],
|
|
2406
|
+
linkLabel
|
|
2407
|
+
);
|
|
2408
|
+
const linkId = assertUuid(link2.id, `${linkLabel}.id`);
|
|
2409
|
+
if (linkIds.has(linkId)) {
|
|
2410
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel}.id is duplicate`);
|
|
2411
|
+
}
|
|
2412
|
+
linkIds.add(linkId);
|
|
2413
|
+
if (assertUuid(link2.connectorId, `${linkLabel}.connectorId`) !== connectorId) {
|
|
2414
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel} is unbound`);
|
|
2415
|
+
}
|
|
2416
|
+
const status = stringField(link2, "status", linkLabel);
|
|
2417
|
+
if (!["active", "reconnect_required", "revoked", "expired"].includes(status)) {
|
|
2418
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${linkLabel}.status is invalid`);
|
|
2419
|
+
}
|
|
2420
|
+
const scopes = stringArrayField(link2, "grantedScopes", linkLabel);
|
|
2421
|
+
if (status === "active") {
|
|
2422
|
+
activeCount += 1;
|
|
2423
|
+
if (hasSelection ? selectedLinkId === linkId : activeCount === 1) {
|
|
2424
|
+
activeLink = true;
|
|
2425
|
+
grantedScopes = scopes;
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
if (selectedLinkId === linkId) selectedCount += 1;
|
|
2429
|
+
}
|
|
2430
|
+
if (hasSelection && selectedLinkId !== null && (selectedCount !== 1 || !activeLink) || !hasSelection && activeCount > 1) {
|
|
2431
|
+
throw clientError(
|
|
2432
|
+
"AP_RESPONSE_INVALID",
|
|
2433
|
+
`Admin API response ${label}.selectedLinkId is invalid`
|
|
2434
|
+
);
|
|
2435
|
+
}
|
|
2436
|
+
if (hasSelection && selectedLinkId === null) {
|
|
2437
|
+
activeLink = false;
|
|
2438
|
+
grantedScopes = [];
|
|
2439
|
+
}
|
|
2440
|
+
const mcpResource = Object.hasOwn(state, "mcpResource") ? nullableStringField(state, "mcpResource", label) : null;
|
|
2441
|
+
if (mcpResource !== null) {
|
|
2442
|
+
let parsed;
|
|
2443
|
+
try {
|
|
2444
|
+
parsed = new URL(mcpResource);
|
|
2445
|
+
} catch {
|
|
2446
|
+
throw clientError(
|
|
2447
|
+
"AP_RESPONSE_INVALID",
|
|
2448
|
+
`Admin API response ${label}.mcpResource is invalid`
|
|
2449
|
+
);
|
|
2450
|
+
}
|
|
2451
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash || parsed.search) {
|
|
2452
|
+
throw clientError(
|
|
2453
|
+
"AP_RESPONSE_INVALID",
|
|
2454
|
+
`Admin API response ${label}.mcpResource is invalid`
|
|
2455
|
+
);
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
const smokeToolsValue = Object.hasOwn(state, "smokeTools") ? state.smokeTools : [];
|
|
2459
|
+
if (!Array.isArray(smokeToolsValue)) {
|
|
2460
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.smokeTools is invalid`);
|
|
2461
|
+
}
|
|
2462
|
+
const smokeTools = smokeToolsValue.map(
|
|
2463
|
+
(entry, index) => {
|
|
2464
|
+
const toolLabel = `${label}.smokeTools[${index}]`;
|
|
2465
|
+
const tool = asObject(entry, toolLabel);
|
|
2466
|
+
exactRequiredKeys(tool, ["id", "versionId", "name", "scopes"], toolLabel);
|
|
2467
|
+
const name = stringField(tool, "name", toolLabel);
|
|
2468
|
+
const scopes = stringArrayField(tool, "scopes", toolLabel);
|
|
2469
|
+
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))) {
|
|
2470
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${toolLabel} is invalid`);
|
|
2471
|
+
}
|
|
2472
|
+
return {
|
|
2473
|
+
id: assertUuid(tool.id, `${toolLabel}.id`),
|
|
2474
|
+
versionId: assertUuid(tool.versionId, `${toolLabel}.versionId`),
|
|
2475
|
+
name,
|
|
2476
|
+
scopes
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
);
|
|
2480
|
+
if (!Array.isArray(state.scopes) || !Array.isArray(state.diagnostics)) {
|
|
2481
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label} is invalid`);
|
|
2482
|
+
}
|
|
2483
|
+
for (const [index, entry] of state.scopes.entries()) {
|
|
2484
|
+
const scopeLabel = `${label}.scopes[${index}]`;
|
|
2485
|
+
const scope = asObject(entry, scopeLabel);
|
|
2486
|
+
exactKeys(scope, ["name", "description", "riskLevel", "required"], scopeLabel);
|
|
2487
|
+
stringField(scope, "name", scopeLabel);
|
|
2488
|
+
if (scope.description !== null) stringField(scope, "description", scopeLabel);
|
|
2489
|
+
stringField(scope, "riskLevel", scopeLabel);
|
|
2490
|
+
booleanField(scope, "required", scopeLabel);
|
|
2491
|
+
}
|
|
2492
|
+
const diagnostics = state.diagnostics.map(
|
|
2493
|
+
(entry, index) => {
|
|
2494
|
+
const diagnosticLabel = `${label}.diagnostics[${index}]`;
|
|
2495
|
+
const diagnostic = asObject(entry, diagnosticLabel);
|
|
2496
|
+
exactKeys(diagnostic, ["id", "status", "detail"], diagnosticLabel);
|
|
2497
|
+
const status = diagnostic.status;
|
|
2498
|
+
if (status !== "pass" && status !== "pending" && status !== "fail") {
|
|
2499
|
+
throw clientError(
|
|
2500
|
+
"AP_RESPONSE_INVALID",
|
|
2501
|
+
`Admin API response ${diagnosticLabel} is invalid`
|
|
2502
|
+
);
|
|
2503
|
+
}
|
|
2504
|
+
return {
|
|
2505
|
+
id: stringField(diagnostic, "id", diagnosticLabel),
|
|
2506
|
+
status,
|
|
2507
|
+
detail: stringField(diagnostic, "detail", diagnosticLabel)
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
);
|
|
2511
|
+
if (state.currentStep !== "metadata" && state.currentStep !== "test_account" && state.currentStep !== "diagnostics") {
|
|
2512
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.currentStep is invalid`);
|
|
2513
|
+
}
|
|
2514
|
+
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") {
|
|
2515
|
+
throw clientError("AP_RESPONSE_INVALID", `Admin API response ${label}.nextAction is invalid`);
|
|
2516
|
+
}
|
|
2517
|
+
const allGreen = booleanField(state, "allGreen", label);
|
|
2518
|
+
if (allGreen !== diagnostics.every((candidate) => candidate.status === "pass")) {
|
|
2519
|
+
throw clientError(
|
|
2520
|
+
"AP_RESPONSE_INVALID",
|
|
2521
|
+
`Admin API response ${label}.allGreen is inconsistent`
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
return {
|
|
2525
|
+
connectorId,
|
|
2526
|
+
issuer,
|
|
2527
|
+
selectedLinkId,
|
|
2528
|
+
activeLink,
|
|
2529
|
+
mcpResource,
|
|
2530
|
+
smokeTools,
|
|
2531
|
+
requiredScopes: stringArrayField(state, "requiredScopes", label),
|
|
2532
|
+
grantedScopes,
|
|
2533
|
+
redirectUri: nullableStringField(state, "redirectUri", label),
|
|
2534
|
+
diagnostics,
|
|
2535
|
+
allGreen,
|
|
2536
|
+
currentStep: state.currentStep,
|
|
2537
|
+
nextAction: state.nextAction
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2265
2540
|
function nullableNonnegativeIntegerField(record, key, label) {
|
|
2266
2541
|
const value = record[key];
|
|
2267
2542
|
if (value === null) {
|
|
@@ -6089,7 +6364,7 @@ var import_node_crypto11 = require("crypto");
|
|
|
6089
6364
|
var import_node_path11 = require("path");
|
|
6090
6365
|
var import_promises2 = require("readline/promises");
|
|
6091
6366
|
var import_localization7 = require("@andpipes/localization");
|
|
6092
|
-
var
|
|
6367
|
+
var import_tool_contract8 = require("@andpipes/tool-contract");
|
|
6093
6368
|
|
|
6094
6369
|
// src/lib/init-manifest.ts
|
|
6095
6370
|
var import_node_fs10 = require("fs");
|
|
@@ -6612,6 +6887,93 @@ function writeInitManifestNoReplace(plan, manifest, runtime) {
|
|
|
6612
6887
|
});
|
|
6613
6888
|
}
|
|
6614
6889
|
|
|
6890
|
+
// src/lib/openapi-classification.ts
|
|
6891
|
+
var import_tool_contract6 = require("@andpipes/tool-contract");
|
|
6892
|
+
var SIDE_EFFECT_FREE_RE = /^([A-Za-z0-9][A-Za-z0-9._:-]{0,199})=(read|draft)$/u;
|
|
6893
|
+
function parseAuthModeOption(value) {
|
|
6894
|
+
if (value === void 0) return void 0;
|
|
6895
|
+
if (!(0, import_tool_contract6.isOpenApiImportUpstreamAuthMode)(value)) {
|
|
6896
|
+
throw new UsageError("--auth-mode \u306F existing_oauth \u307E\u305F\u306F token_exchange \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
6897
|
+
}
|
|
6898
|
+
return value;
|
|
6899
|
+
}
|
|
6900
|
+
function parseSideEffectFreeOptions(values) {
|
|
6901
|
+
if (values === void 0 || values.length === 0) return [];
|
|
6902
|
+
if (values.length > import_tool_contract6.OPENAPI_IMPORT_MAX_OPERATIONS) {
|
|
6903
|
+
throw new UsageError(
|
|
6904
|
+
`--side-effect-free \u306F${import_tool_contract6.OPENAPI_IMPORT_MAX_OPERATIONS}\u4EF6\u4EE5\u4E0B\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`
|
|
6905
|
+
);
|
|
6906
|
+
}
|
|
6907
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6908
|
+
return values.map((value) => {
|
|
6909
|
+
const match = SIDE_EFFECT_FREE_RE.exec(value);
|
|
6910
|
+
if (!match?.[1] || !match[2]) {
|
|
6911
|
+
throw new UsageError(
|
|
6912
|
+
"--side-effect-free \u306F <toolName>=read \u307E\u305F\u306F <toolName>=draft \u306E\u5F62\u5F0F\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
6913
|
+
);
|
|
6914
|
+
}
|
|
6915
|
+
if (seen.has(match[1])) {
|
|
6916
|
+
throw new UsageError(`--side-effect-free \u3067\u540C\u3058tool\u540D\u3092\u91CD\u8907\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093: ${match[1]}`);
|
|
6917
|
+
}
|
|
6918
|
+
seen.add(match[1]);
|
|
6919
|
+
return { toolName: match[1], riskLevel: match[2] };
|
|
6920
|
+
});
|
|
6921
|
+
}
|
|
6922
|
+
function postOperationList(operations) {
|
|
6923
|
+
const posts = operations.filter((operation) => operation.method === "POST");
|
|
6924
|
+
return posts.length === 0 ? " \uFF08POST\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF09" : posts.map((operation) => ` - ${operation.toolName} (POST ${operation.path})`).join("\n");
|
|
6925
|
+
}
|
|
6926
|
+
function resolveOperationRiskOverrides(requests, operations) {
|
|
6927
|
+
return requests.map((request) => {
|
|
6928
|
+
const operation = operations.find((candidate) => candidate.toolName === request.toolName);
|
|
6929
|
+
if (operation?.method !== "POST") {
|
|
6930
|
+
throw new UsageError(
|
|
6931
|
+
`--side-effect-free \u306F\u3053\u306EOpenAPI\u306EPOST\u64CD\u4F5C\u3060\u3051\u306B\u6307\u5B9A\u3067\u304D\u307E\u3059: ${request.toolName}
|
|
6932
|
+
\u6307\u5B9A\u3067\u304D\u308BPOST\u64CD\u4F5C:
|
|
6933
|
+
${postOperationList(operations)}`
|
|
6934
|
+
);
|
|
6935
|
+
}
|
|
6936
|
+
return {
|
|
6937
|
+
toolName: operation.toolName,
|
|
6938
|
+
method: "POST",
|
|
6939
|
+
path: operation.path,
|
|
6940
|
+
riskLevel: request.riskLevel
|
|
6941
|
+
};
|
|
6942
|
+
});
|
|
6943
|
+
}
|
|
6944
|
+
function sideEffectFreeGuidance(operations) {
|
|
6945
|
+
const defaults = operations.filter(
|
|
6946
|
+
(operation) => operation.method === "POST" && operation.riskLevel === "write_high"
|
|
6947
|
+
);
|
|
6948
|
+
const first = defaults[0];
|
|
6949
|
+
if (!first) return void 0;
|
|
6950
|
+
return [
|
|
6951
|
+
"\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",
|
|
6952
|
+
...defaults.map((operation) => ` - ${operation.toolName} (POST ${operation.path})`),
|
|
6953
|
+
"\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",
|
|
6954
|
+
" \u53C2\u7167\u3060\u3051\uFF08\u691C\u7D22\u30FB\u5DEE\u5206\u8A08\u7B97\u306A\u3069\uFF09: --side-effect-free <toolName>=read",
|
|
6955
|
+
" \u6848\u3092\u4F5C\u308B\u3060\u3051\uFF08\u53CD\u6620\u306F\u5225\u306E\u66F4\u65B0\u64CD\u4F5C\uFF09: --side-effect-free <toolName>=draft",
|
|
6956
|
+
` \u4F8B: --side-effect-free ${first.toolName}=read`
|
|
6957
|
+
].join("\n");
|
|
6958
|
+
}
|
|
6959
|
+
function authModeMismatchGuidance(mismatch) {
|
|
6960
|
+
const lines = [
|
|
6961
|
+
`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`
|
|
6962
|
+
];
|
|
6963
|
+
if ((0, import_tool_contract6.isOpenApiImportUpstreamAuthMode)(mismatch.connectorAuthMode)) {
|
|
6964
|
+
lines.push(
|
|
6965
|
+
` 1. \u3053\u306Econnector\u3092\u4F7F\u3046: --auth-mode ${mismatch.connectorAuthMode} \u3092\u6307\u5B9A\u3057\u3066\u518D\u5B9F\u884C\u3059\u308B`,
|
|
6966
|
+
` 2. \u53D6\u8FBC\u65B9\u5F0F\u3092\u5909\u3048\u306A\u3044: ${mismatch.requestedAuthMode} \u306Econnector\u3092 --connector \u306B\u6307\u5B9A\u3059\u308B`
|
|
6967
|
+
);
|
|
6968
|
+
} else {
|
|
6969
|
+
lines.push(
|
|
6970
|
+
" OpenAPI\u53D6\u8FBC\u306F existing_oauth \u307E\u305F\u306F token_exchange \u306Econnector\u3060\u3051\u3092\u5BFE\u8C61\u306B\u3067\u304D\u307E\u3059\u3002",
|
|
6971
|
+
" \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"
|
|
6972
|
+
);
|
|
6973
|
+
}
|
|
6974
|
+
return lines.join("\n");
|
|
6975
|
+
}
|
|
6976
|
+
|
|
6615
6977
|
// src/lib/terminal-safe.ts
|
|
6616
6978
|
function isBidirectionalFormatControl(codePoint) {
|
|
6617
6979
|
return codePoint === 1564 || codePoint >= 8206 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
@@ -6648,7 +7010,7 @@ function terminalSafeValue(value) {
|
|
|
6648
7010
|
// src/commands/template.ts
|
|
6649
7011
|
var import_node_crypto10 = require("crypto");
|
|
6650
7012
|
var import_node_path10 = require("path");
|
|
6651
|
-
var
|
|
7013
|
+
var import_tool_contract7 = require("@andpipes/tool-contract");
|
|
6652
7014
|
var BINDINGS_MAX_BYTES = 64 * 1024;
|
|
6653
7015
|
var EXPORT_MAX_BYTES = 1280 * 1024;
|
|
6654
7016
|
var TEMPLATE_ID_RE2 = /^[a-z][a-z0-9._-]{0,63}$/u;
|
|
@@ -6656,7 +7018,7 @@ function createTemplateCommandRuntime(createClient = (profile) => createAdminApi
|
|
|
6656
7018
|
return { createClient, idempotencyKey: import_node_crypto10.randomUUID };
|
|
6657
7019
|
}
|
|
6658
7020
|
function jsonObject(text, label) {
|
|
6659
|
-
const parsed = (0,
|
|
7021
|
+
const parsed = (0, import_tool_contract7.parseToolContract)(text, { format: "json" });
|
|
6660
7022
|
if (!parsed.ok || !parsed.contract || typeof parsed.contract !== "object" || Array.isArray(parsed.contract)) {
|
|
6661
7023
|
throw new UsageError(`${label}\u306Fvalid JSON object\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
|
|
6662
7024
|
}
|
|
@@ -6683,7 +7045,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6683
7045
|
}
|
|
6684
7046
|
let exported;
|
|
6685
7047
|
try {
|
|
6686
|
-
exported = (0,
|
|
7048
|
+
exported = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(source);
|
|
6687
7049
|
} catch {
|
|
6688
7050
|
throw new UsageError("template export artifact\u306Eshape\u304C\u4E0D\u6B63\u3067\u3059");
|
|
6689
7051
|
}
|
|
@@ -6708,7 +7070,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6708
7070
|
}
|
|
6709
7071
|
const bindingSnapshot = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6710
7072
|
const bindingSource = jsonObject(bindingSnapshot.text, "bindings file");
|
|
6711
|
-
const manifest = (0,
|
|
7073
|
+
const manifest = (0, import_tool_contract7.parseExternalSaasTemplate)(source);
|
|
6712
7074
|
const verifiedTemplate = readArtifact(file, EXPORT_MAX_BYTES, "template file");
|
|
6713
7075
|
const verifiedBindings = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6714
7076
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template inputs final root");
|
|
@@ -6720,7 +7082,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6720
7082
|
}
|
|
6721
7083
|
return {
|
|
6722
7084
|
manifest,
|
|
6723
|
-
bindings: (0,
|
|
7085
|
+
bindings: (0, import_tool_contract7.parseOnboardingTemplateBindings)(manifest, bindingSource),
|
|
6724
7086
|
sourceSnapshot: { ...verifiedTemplate.identity, sha256: verifiedTemplate.sha256 }
|
|
6725
7087
|
};
|
|
6726
7088
|
} catch (error) {
|
|
@@ -6749,7 +7111,7 @@ function expectedCurrent(value) {
|
|
|
6749
7111
|
throw new UsageError("--apply\u306B\u306F--expected-current <commitment|none>\u304C\u5FC5\u9808\u3067\u3059");
|
|
6750
7112
|
}
|
|
6751
7113
|
if (value === "none") return null;
|
|
6752
|
-
if (!
|
|
7114
|
+
if (!import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(value)) {
|
|
6753
7115
|
throw new UsageError("--expected-current\u306Fsha256 commitment\u307E\u305F\u306Fnone\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
6754
7116
|
}
|
|
6755
7117
|
return value;
|
|
@@ -6769,7 +7131,7 @@ function applyProof(options) {
|
|
|
6769
7131
|
"\u5148\u306Bdry-run\u306Esafe diff\u3092\u78BA\u8A8D\u3057\u3001--apply --yes\u3067\u660E\u793A\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
6770
7132
|
);
|
|
6771
7133
|
}
|
|
6772
|
-
if (!options.planCommitment || !
|
|
7134
|
+
if (!options.planCommitment || !import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(options.planCommitment)) {
|
|
6773
7135
|
throw new UsageError("--apply\u306B\u306Fdry-run\u3067\u5F97\u305F--plan-commitment\u304C\u5FC5\u9808\u3067\u3059");
|
|
6774
7136
|
}
|
|
6775
7137
|
return {
|
|
@@ -6778,10 +7140,10 @@ function applyProof(options) {
|
|
|
6778
7140
|
};
|
|
6779
7141
|
}
|
|
6780
7142
|
function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
6781
|
-
const parsedPlan = (0,
|
|
6782
|
-
const templateCommitment = (0,
|
|
6783
|
-
const bindingCommitment = (0,
|
|
6784
|
-
const applicationCommitment = (0,
|
|
7143
|
+
const parsedPlan = (0, import_tool_contract7.parseOnboardingTemplateSafePlanDto)(plan);
|
|
7144
|
+
const templateCommitment = (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest);
|
|
7145
|
+
const bindingCommitment = (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings);
|
|
7146
|
+
const applicationCommitment = (0, import_tool_contract7.onboardingTemplateApplicationCommitment)({
|
|
6785
7147
|
projectId,
|
|
6786
7148
|
templateCommitment,
|
|
6787
7149
|
bindingCommitment
|
|
@@ -6791,10 +7153,10 @@ function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
|
6791
7153
|
}
|
|
6792
7154
|
}
|
|
6793
7155
|
function assertApplyMatchesLocal(result, projectId, loaded, planCommitment) {
|
|
6794
|
-
const parsed = (0,
|
|
6795
|
-
const templateCommitment = (0,
|
|
6796
|
-
const bindingCommitment = (0,
|
|
6797
|
-
const applicationCommitment = (0,
|
|
7156
|
+
const parsed = (0, import_tool_contract7.parseOnboardingTemplateApplyDto)(result);
|
|
7157
|
+
const templateCommitment = (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest);
|
|
7158
|
+
const bindingCommitment = (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings);
|
|
7159
|
+
const applicationCommitment = (0, import_tool_contract7.onboardingTemplateApplicationCommitment)({
|
|
6798
7160
|
projectId,
|
|
6799
7161
|
templateCommitment,
|
|
6800
7162
|
bindingCommitment
|
|
@@ -6844,7 +7206,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6844
7206
|
const client = runtime.createClient(options.profile ?? DEFAULT_PROFILE_NAME);
|
|
6845
7207
|
if (!proof) {
|
|
6846
7208
|
const plan = await client.planOnboardingTemplateRollback(projectId, templateId, targetRevision);
|
|
6847
|
-
const parsed2 = (0,
|
|
7209
|
+
const parsed2 = (0, import_tool_contract7.parseOnboardingTemplateSafePlanDto)(plan);
|
|
6848
7210
|
if (parsed2.projectId !== projectId || parsed2.templateId !== templateId || parsed2.operation !== "rollback" || parsed2.rollbackFromRevision !== targetRevision || parsed2.currentApplicationCommitment === null) {
|
|
6849
7211
|
throw new UsageError("Admin API\u306Erollback plan\u304C\u8981\u6C42scope\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6850
7212
|
}
|
|
@@ -6875,7 +7237,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6875
7237
|
confirmed: true
|
|
6876
7238
|
}
|
|
6877
7239
|
);
|
|
6878
|
-
const parsed = (0,
|
|
7240
|
+
const parsed = (0, import_tool_contract7.parseOnboardingTemplateApplyDto)(result);
|
|
6879
7241
|
if (parsed.projectId !== projectId || parsed.templateId !== templateId || parsed.operation !== "rollback" || parsed.rollbackFromRevision !== targetRevision || parsed.planCommitment !== proof.planCommitment || parsed.applicationCommitment === proof.expectedCurrent) {
|
|
6880
7242
|
throw new UsageError("Admin API\u306Erollback\u7D50\u679C\u304C\u78BA\u8A8D\u6E08\u307F\u8A08\u753B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6881
7243
|
}
|
|
@@ -6892,8 +7254,8 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
6892
7254
|
valid: true,
|
|
6893
7255
|
templateId: loaded.manifest.templateId,
|
|
6894
7256
|
templateVersion: loaded.manifest.version,
|
|
6895
|
-
templateCommitment: (0,
|
|
6896
|
-
bindingCommitment: (0,
|
|
7257
|
+
templateCommitment: (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest),
|
|
7258
|
+
bindingCommitment: (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings),
|
|
6897
7259
|
...loaded.exportApplicationCommitment ? { applicationCommitment: loaded.exportApplicationCommitment } : {}
|
|
6898
7260
|
});
|
|
6899
7261
|
});
|
|
@@ -6912,7 +7274,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
6912
7274
|
const projectId = assertProjectId(options.project);
|
|
6913
7275
|
const templateId = canonicalTemplateId(options.template);
|
|
6914
7276
|
const anchor = captureLocalRootPath(cwd());
|
|
6915
|
-
const result = (0,
|
|
7277
|
+
const result = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(
|
|
6916
7278
|
await runtime.createClient(options.profile).exportOnboardingTemplate(projectId, templateId)
|
|
6917
7279
|
);
|
|
6918
7280
|
if (result.projectId !== projectId || result.manifest.templateId !== templateId) {
|
|
@@ -6968,8 +7330,13 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
6968
7330
|
if (options.openapi !== void 0 && options.project === void 0) {
|
|
6969
7331
|
throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
|
|
6970
7332
|
}
|
|
6971
|
-
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
|
|
6972
|
-
throw new UsageError(
|
|
7333
|
+
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0 || options.authMode !== void 0 || (options.sideEffectFree?.length ?? 0) > 0)) {
|
|
7334
|
+
throw new UsageError(
|
|
7335
|
+
messages.optionRequires(
|
|
7336
|
+
"--base-url / --service-name / --auth-mode / --side-effect-free",
|
|
7337
|
+
"--openapi"
|
|
7338
|
+
)
|
|
7339
|
+
);
|
|
6973
7340
|
}
|
|
6974
7341
|
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)) {
|
|
6975
7342
|
throw new UsageError(
|
|
@@ -6994,26 +7361,36 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
6994
7361
|
}
|
|
6995
7362
|
}
|
|
6996
7363
|
async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
6997
|
-
if (options.openapi === void 0) return { options, anchor };
|
|
7364
|
+
if (options.openapi === void 0) return { options, anchor, notices: [] };
|
|
7365
|
+
const upstreamAuthMode = parseAuthModeOption(options.authMode);
|
|
7366
|
+
const sideEffectFree = parseSideEffectFreeOptions(options.sideEffectFree);
|
|
6998
7367
|
const contractPath = "tool-contract.json";
|
|
6999
7368
|
prepareLocalOrThrow(runtime, anchor, contractPath, messages);
|
|
7000
7369
|
const source = withAnchoredLocalRoot(
|
|
7001
7370
|
anchor.root,
|
|
7002
7371
|
anchor.rootIdentity,
|
|
7003
7372
|
() => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
|
|
7004
|
-
maxBytes:
|
|
7373
|
+
maxBytes: import_tool_contract8.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
7005
7374
|
root: anchor.root
|
|
7006
7375
|
})
|
|
7007
7376
|
);
|
|
7008
7377
|
let imported;
|
|
7009
7378
|
try {
|
|
7010
|
-
|
|
7379
|
+
const importOptions = {
|
|
7011
7380
|
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
7012
7381
|
...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
|
|
7013
|
-
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
|
|
7014
|
-
|
|
7382
|
+
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName },
|
|
7383
|
+
...upstreamAuthMode === void 0 ? {} : { upstreamAuthMode }
|
|
7384
|
+
};
|
|
7385
|
+
imported = (0, import_tool_contract8.importOpenApi)(source.text, importOptions);
|
|
7386
|
+
if (sideEffectFree.length > 0) {
|
|
7387
|
+
imported = (0, import_tool_contract8.importOpenApi)(source.text, {
|
|
7388
|
+
...importOptions,
|
|
7389
|
+
operationRiskOverrides: resolveOperationRiskOverrides(sideEffectFree, imported.operations)
|
|
7390
|
+
});
|
|
7391
|
+
}
|
|
7015
7392
|
} catch (error) {
|
|
7016
|
-
if (error instanceof
|
|
7393
|
+
if (error instanceof import_tool_contract8.OpenApiImportError) {
|
|
7017
7394
|
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
7018
7395
|
}
|
|
7019
7396
|
throw error;
|
|
@@ -7058,13 +7435,27 @@ async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
|
7058
7435
|
messages.failure("local_file_changed")
|
|
7059
7436
|
);
|
|
7060
7437
|
}
|
|
7438
|
+
const notices = [];
|
|
7439
|
+
if (upstreamAuthMode === void 0) {
|
|
7440
|
+
notices.push(
|
|
7441
|
+
"\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"
|
|
7442
|
+
);
|
|
7443
|
+
}
|
|
7444
|
+
const guidance = sideEffectFreeGuidance(imported.operations);
|
|
7445
|
+
if (guidance) {
|
|
7446
|
+
notices.push(
|
|
7447
|
+
`${guidance}
|
|
7448
|
+
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`
|
|
7449
|
+
);
|
|
7450
|
+
}
|
|
7061
7451
|
return {
|
|
7062
7452
|
options: {
|
|
7063
7453
|
project: options.project,
|
|
7064
7454
|
contract: contractPath,
|
|
7065
7455
|
profile: options.profile
|
|
7066
7456
|
},
|
|
7067
|
-
anchor: refreshedAnchor
|
|
7457
|
+
anchor: refreshedAnchor,
|
|
7458
|
+
notices
|
|
7068
7459
|
};
|
|
7069
7460
|
}
|
|
7070
7461
|
async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
@@ -7117,7 +7508,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7117
7508
|
contractPath,
|
|
7118
7509
|
anchor.root,
|
|
7119
7510
|
contractText,
|
|
7120
|
-
|
|
7511
|
+
import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7121
7512
|
{ expectedRootIdentity: anchor.rootIdentity }
|
|
7122
7513
|
);
|
|
7123
7514
|
} catch (error) {
|
|
@@ -7125,7 +7516,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7125
7516
|
try {
|
|
7126
7517
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template contract fallback");
|
|
7127
7518
|
const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
|
|
7128
|
-
maxBytes:
|
|
7519
|
+
maxBytes: import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7129
7520
|
root: anchor.root,
|
|
7130
7521
|
directChildOnly: true
|
|
7131
7522
|
});
|
|
@@ -7586,6 +7977,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7586
7977
|
const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
|
|
7587
7978
|
rootAnchor = materialized.anchor;
|
|
7588
7979
|
mode = normalizeInitOptions(materialized.options, messages);
|
|
7980
|
+
for (const notice of materialized.notices) interactive(writer, notice);
|
|
7589
7981
|
}
|
|
7590
7982
|
if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
|
|
7591
7983
|
let actionMode;
|
|
@@ -7661,7 +8053,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7661
8053
|
idempotencyKey: actionMode.connectorCreate.idempotencyKey,
|
|
7662
8054
|
connector: actionMode.connectorCreate.input
|
|
7663
8055
|
});
|
|
7664
|
-
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,
|
|
8056
|
+
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)) {
|
|
7665
8057
|
throw new InitCommandError(
|
|
7666
8058
|
"AP_RESPONSE_INVALID",
|
|
7667
8059
|
"template_connector_create_mismatch",
|
|
@@ -7689,6 +8081,14 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7689
8081
|
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) {
|
|
7690
8082
|
const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
|
|
7691
8083
|
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(
|
|
8084
|
+
"--auth-mode <mode>",
|
|
8085
|
+
"OpenAPI upstream auth mode matching the publish connector: existing_oauth or token_exchange (default token_exchange)"
|
|
8086
|
+
).option(
|
|
8087
|
+
"--side-effect-free <toolName=level>",
|
|
8088
|
+
"Explicitly classify a POST that does not store, change or send data as read or draft (repeatable)",
|
|
8089
|
+
(value, previous) => [...previous, value],
|
|
8090
|
+
[]
|
|
8091
|
+
).option(
|
|
7692
8092
|
"--create-connector",
|
|
7693
8093
|
"Create the template connector through the existing Admin API policy boundary",
|
|
7694
8094
|
false
|
|
@@ -7796,6 +8196,14 @@ function buildInitTemplate(provider) {
|
|
|
7796
8196
|
scopes: ["openid", "profile"]
|
|
7797
8197
|
};
|
|
7798
8198
|
}
|
|
8199
|
+
function upstreamOAuthWizardUrl(profile, projectId, connectorId) {
|
|
8200
|
+
const record = getProfile(profile);
|
|
8201
|
+
if (!record)
|
|
8202
|
+
throw new UsageError(`\u8A8D\u8A3Cprofile ${profile} \u304C\u3042\u308A\u307E\u305B\u3093\u3002andpipe login\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044`);
|
|
8203
|
+
const url = new URL(`/projects/${projectId}/oauth`, new URL(record.verificationUriBase).origin);
|
|
8204
|
+
url.searchParams.set("connector", connectorId);
|
|
8205
|
+
return url.toString();
|
|
8206
|
+
}
|
|
7799
8207
|
async function loadOAuthMetadata(opts, locale) {
|
|
7800
8208
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7801
8209
|
if (opts.file && opts.issuer) {
|
|
@@ -7825,7 +8233,7 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
7825
8233
|
info(writer, messages.oauth.metadataOk);
|
|
7826
8234
|
}
|
|
7827
8235
|
}
|
|
7828
|
-
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8236
|
+
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE, dependencies = {}) {
|
|
7829
8237
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7830
8238
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
7831
8239
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
@@ -7906,6 +8314,43 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
7906
8314
|
metadata.command("validate").description(messages.oauth.validateDescription).option("--file <path>", messages.common.metadataFileOption).option("--issuer <url>", messages.common.issuerOption).action(async (opts) => {
|
|
7907
8315
|
await runOAuthMetadataValidate(opts, writer, locale);
|
|
7908
8316
|
});
|
|
8317
|
+
const connect = oauth.command("connect").description(
|
|
8318
|
+
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"
|
|
8319
|
+
);
|
|
8320
|
+
connect.command("status").description(
|
|
8321
|
+
locale === "ja" ? "\u63A5\u7D9A\u72B6\u614B\u3068\u6B21\u306E\u64CD\u4F5C\u3092\u8868\u793A" : "Show connection state and next action"
|
|
8322
|
+
).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) => {
|
|
8323
|
+
const state = await createAdminApiClient({
|
|
8324
|
+
profile: opts.profile
|
|
8325
|
+
}).getUpstreamOAuthConnectionState(assertProjectId(opts.project), opts.connector);
|
|
8326
|
+
json(writer, state);
|
|
8327
|
+
if (!state.allGreen) process.exitCode = 1;
|
|
8328
|
+
});
|
|
8329
|
+
connect.command("open").description(
|
|
8330
|
+
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"
|
|
8331
|
+
).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--connector <connector>", "\u63A5\u7D9A\u5BFE\u8C61connector UUID").option("--profile <name>", messages.common.targetProfileOption, DEFAULT_PROFILE_NAME).option(
|
|
8332
|
+
"--no-browser",
|
|
8333
|
+
locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u958B\u304B\u305AURL\u3060\u3051\u8868\u793A" : "Print the URL without opening a browser"
|
|
8334
|
+
).action(
|
|
8335
|
+
async (opts) => {
|
|
8336
|
+
const projectId = assertProjectId(opts.project);
|
|
8337
|
+
const state = await createAdminApiClient({
|
|
8338
|
+
profile: opts.profile
|
|
8339
|
+
}).getUpstreamOAuthConnectionState(projectId, opts.connector);
|
|
8340
|
+
json(writer, state);
|
|
8341
|
+
const url = upstreamOAuthWizardUrl(opts.profile, projectId, opts.connector);
|
|
8342
|
+
info(
|
|
8343
|
+
writer,
|
|
8344
|
+
locale === "ja" ? `Web Admin\u3067\u7D9A\u3051\u3066\u304F\u3060\u3055\u3044: ${url}` : `Continue in Web Admin: ${url}`
|
|
8345
|
+
);
|
|
8346
|
+
if (opts.browser) {
|
|
8347
|
+
try {
|
|
8348
|
+
(dependencies.openBrowser ?? openBrowser)(url);
|
|
8349
|
+
} catch {
|
|
8350
|
+
}
|
|
8351
|
+
}
|
|
8352
|
+
}
|
|
8353
|
+
);
|
|
7909
8354
|
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) => {
|
|
7910
8355
|
const projectId = assertProjectId(opts.project);
|
|
7911
8356
|
const result = await createAdminApiClient({ profile: opts.profile }).testOAuthLogin(
|
|
@@ -7920,7 +8365,7 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
7920
8365
|
// src/commands/openapi.ts
|
|
7921
8366
|
var import_node_crypto12 = require("crypto");
|
|
7922
8367
|
var import_node_path12 = require("path");
|
|
7923
|
-
var
|
|
8368
|
+
var import_tool_contract9 = require("@andpipes/tool-contract");
|
|
7924
8369
|
function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
7925
8370
|
return { createClient, idempotencyKey: import_node_crypto12.randomUUID };
|
|
7926
8371
|
}
|
|
@@ -7956,9 +8401,17 @@ function normalizedOptions(options) {
|
|
|
7956
8401
|
apply,
|
|
7957
8402
|
yes,
|
|
7958
8403
|
...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
|
|
7959
|
-
...options.planCommitment !== void 0 ? { planCommitment: options.planCommitment } : {}
|
|
8404
|
+
...options.planCommitment !== void 0 ? { planCommitment: options.planCommitment } : {},
|
|
8405
|
+
...options.authMode !== void 0 ? { upstreamAuthMode: parseAuthModeOption(options.authMode) } : {},
|
|
8406
|
+
sideEffectFree: parseSideEffectFreeOptions(options.sideEffectFree)
|
|
7960
8407
|
};
|
|
7961
8408
|
}
|
|
8409
|
+
function rethrowWithAuthModeGuidance(error) {
|
|
8410
|
+
if (error instanceof AdminApiClientError && error.openApiAuthModeMismatch) {
|
|
8411
|
+
throw new UsageError(authModeMismatchGuidance(error.openApiAuthModeMismatch));
|
|
8412
|
+
}
|
|
8413
|
+
throw error;
|
|
8414
|
+
}
|
|
7962
8415
|
async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
7963
8416
|
const normalized = normalizedOptions(options);
|
|
7964
8417
|
if (normalized.apply && !normalized.yes) {
|
|
@@ -7971,39 +8424,88 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
7971
8424
|
throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
|
|
7972
8425
|
}
|
|
7973
8426
|
const snapshot = readBoundedLocalFileSnapshot((0, import_node_path12.resolve)(cwd, normalized.file), {
|
|
7974
|
-
maxBytes:
|
|
8427
|
+
maxBytes: import_tool_contract9.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
7975
8428
|
root: cwd
|
|
7976
8429
|
});
|
|
7977
|
-
const
|
|
8430
|
+
const baseRequest = {
|
|
7978
8431
|
source: snapshot.text,
|
|
7979
8432
|
connectorId: normalized.connectorId,
|
|
7980
8433
|
...normalized.format !== void 0 ? { format: normalized.format } : {},
|
|
7981
8434
|
...normalized.baseUrl !== void 0 ? { baseUrl: normalized.baseUrl } : {},
|
|
7982
8435
|
...normalized.serviceName !== void 0 ? { serviceName: normalized.serviceName } : {},
|
|
7983
|
-
...normalized.
|
|
8436
|
+
...normalized.upstreamAuthMode !== void 0 ? { upstreamAuthMode: normalized.upstreamAuthMode } : {}
|
|
7984
8437
|
};
|
|
7985
8438
|
const client = runtime.createClient(normalized.profile);
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
if (result2.sourceCommitment !== snapshot.sha256) {
|
|
8439
|
+
const assertSource = (sourceCommitment) => {
|
|
8440
|
+
if (sourceCommitment !== snapshot.sha256) {
|
|
7989
8441
|
throw new UsageError("Admin API\u306Esource commitment\u304Clocal file\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
7990
8442
|
}
|
|
7991
|
-
|
|
8443
|
+
};
|
|
8444
|
+
let overrides = [];
|
|
8445
|
+
if (normalized.sideEffectFree.length > 0) {
|
|
8446
|
+
if (normalized.apply) {
|
|
8447
|
+
try {
|
|
8448
|
+
const unclassified = (0, import_tool_contract9.importOpenApi)(snapshot.text, {
|
|
8449
|
+
format: normalized.format,
|
|
8450
|
+
baseUrl: normalized.baseUrl,
|
|
8451
|
+
serviceName: normalized.serviceName,
|
|
8452
|
+
upstreamAuthMode: normalized.upstreamAuthMode
|
|
8453
|
+
});
|
|
8454
|
+
overrides = resolveOperationRiskOverrides(
|
|
8455
|
+
normalized.sideEffectFree,
|
|
8456
|
+
unclassified.operations
|
|
8457
|
+
);
|
|
8458
|
+
} catch (error) {
|
|
8459
|
+
if (error instanceof import_tool_contract9.OpenApiImportError) {
|
|
8460
|
+
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
8461
|
+
}
|
|
8462
|
+
throw error;
|
|
8463
|
+
}
|
|
8464
|
+
} else {
|
|
8465
|
+
const unclassified = await client.planOpenApiImport(normalized.project, baseRequest).catch(rethrowWithAuthModeGuidance);
|
|
8466
|
+
assertSource(unclassified.sourceCommitment);
|
|
8467
|
+
overrides = resolveOperationRiskOverrides(normalized.sideEffectFree, unclassified.operations);
|
|
8468
|
+
}
|
|
8469
|
+
}
|
|
8470
|
+
const request = {
|
|
8471
|
+
...baseRequest,
|
|
8472
|
+
...overrides.length > 0 ? { operationRiskOverrides: overrides } : {},
|
|
8473
|
+
...normalized.planCommitment !== void 0 ? { expectedPlanCommitment: normalized.planCommitment } : {}
|
|
8474
|
+
};
|
|
8475
|
+
const classification = {
|
|
8476
|
+
upstreamAuthMode: normalized.upstreamAuthMode ?? "token_exchange",
|
|
8477
|
+
operationRiskOverrides: overrides
|
|
8478
|
+
};
|
|
8479
|
+
if (!normalized.apply) {
|
|
8480
|
+
const result2 = await client.planOpenApiImport(normalized.project, request).catch(rethrowWithAuthModeGuidance);
|
|
8481
|
+
assertSource(result2.sourceCommitment);
|
|
8482
|
+
json(writer, { mode: "preview", ...classification, ...result2 });
|
|
8483
|
+
const guidance = sideEffectFreeGuidance(result2.operations);
|
|
8484
|
+
if (guidance) interactive(writer, guidance);
|
|
7992
8485
|
return;
|
|
7993
8486
|
}
|
|
7994
8487
|
const result = await client.applyOpenApiImport(
|
|
7995
8488
|
normalized.project,
|
|
7996
8489
|
normalized.idempotencyKey ?? runtime.idempotencyKey(),
|
|
7997
8490
|
request
|
|
7998
|
-
);
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8491
|
+
).catch(rethrowWithAuthModeGuidance);
|
|
8492
|
+
assertSource(result.sourceCommitment);
|
|
8493
|
+
json(writer, { mode: "draft_created", ...classification, ...result });
|
|
8494
|
+
}
|
|
8495
|
+
function collect(value, previous) {
|
|
8496
|
+
return [...previous, value];
|
|
8003
8497
|
}
|
|
8004
8498
|
function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
8005
8499
|
const openapi = program.command("openapi").description("OpenAPI\u304B\u3089Tool Contract draft\u3092\u63D0\u6848\u3059\u308B");
|
|
8006
|
-
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").
|
|
8500
|
+
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(
|
|
8501
|
+
"--auth-mode <mode>",
|
|
8502
|
+
"connector\u3068\u540C\u3058\u8A8D\u8A3C\u65B9\u5F0F\uFF08existing_oauth \u307E\u305F\u306F token_exchange\u3002\u7701\u7565\u6642\u306Ftoken_exchange\uFF09"
|
|
8503
|
+
).option(
|
|
8504
|
+
"--side-effect-free <toolName=level>",
|
|
8505
|
+
"\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",
|
|
8506
|
+
collect,
|
|
8507
|
+
[]
|
|
8508
|
+
).action(
|
|
8007
8509
|
(options) => runOpenApiImportCommand(options, writer, cwd(), runtime)
|
|
8008
8510
|
);
|
|
8009
8511
|
}
|
|
@@ -8011,7 +8513,7 @@ function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRunt
|
|
|
8011
8513
|
// src/commands/publish.ts
|
|
8012
8514
|
var import_node_crypto13 = require("crypto");
|
|
8013
8515
|
var import_localization10 = require("@andpipes/localization");
|
|
8014
|
-
var
|
|
8516
|
+
var import_tool_contract10 = require("@andpipes/tool-contract");
|
|
8015
8517
|
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;
|
|
8016
8518
|
var SAFE_AP_CODE_RE2 = /^AP_[A-Z0-9_]{1,64}$/u;
|
|
8017
8519
|
var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
@@ -8148,7 +8650,7 @@ function responseInvalid(reason, messages) {
|
|
|
8148
8650
|
}
|
|
8149
8651
|
function assertCanonicalResponseSize(value, reason, messages, maxBytes = PUBLICATION_RESPONSE_MAX_BYTES) {
|
|
8150
8652
|
try {
|
|
8151
|
-
(0,
|
|
8653
|
+
(0, import_tool_contract10.assertCanonicalPublicationSize)(value, maxBytes);
|
|
8152
8654
|
} catch {
|
|
8153
8655
|
throw responseInvalid(reason, messages);
|
|
8154
8656
|
}
|
|
@@ -8157,7 +8659,7 @@ function isCanonicalUuid(value) {
|
|
|
8157
8659
|
return typeof value === "string" && UUID_RE6.test(value);
|
|
8158
8660
|
}
|
|
8159
8661
|
function isCommitment(value) {
|
|
8160
|
-
return typeof value === "string" &&
|
|
8662
|
+
return typeof value === "string" && import_tool_contract10.PUBLICATION_SHA256_COMMITMENT_RE.test(value);
|
|
8161
8663
|
}
|
|
8162
8664
|
function isCanonicalTimestamp(value) {
|
|
8163
8665
|
if (typeof value !== "string" || value.length > 64) return false;
|
|
@@ -8166,12 +8668,12 @@ function isCanonicalTimestamp(value) {
|
|
|
8166
8668
|
}
|
|
8167
8669
|
function isStrictlySorted(values) {
|
|
8168
8670
|
return values.every(
|
|
8169
|
-
(value, index) => index === 0 || (0,
|
|
8671
|
+
(value, index) => index === 0 || (0, import_tool_contract10.comparePublicationUnicodeCodePoints)(values[index - 1], value) < 0
|
|
8170
8672
|
);
|
|
8171
8673
|
}
|
|
8172
8674
|
function parseWarnings(value, messages) {
|
|
8173
8675
|
try {
|
|
8174
|
-
return (0,
|
|
8676
|
+
return (0, import_tool_contract10.parsePublicationWarningsDto)(value);
|
|
8175
8677
|
} catch {
|
|
8176
8678
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8177
8679
|
}
|
|
@@ -8187,7 +8689,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8187
8689
|
const blockedReasons = plan.blockedReasons;
|
|
8188
8690
|
let safeDiff;
|
|
8189
8691
|
try {
|
|
8190
|
-
safeDiff = (0,
|
|
8692
|
+
safeDiff = (0, import_tool_contract10.parsePublicationSafeDiffDto)({
|
|
8191
8693
|
tools: plan.tools,
|
|
8192
8694
|
retainedTools: plan.retainedTools,
|
|
8193
8695
|
warnings: plan.warnings
|
|
@@ -8201,7 +8703,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8201
8703
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8202
8704
|
}
|
|
8203
8705
|
const warnings = safeDiff.warnings;
|
|
8204
|
-
const expectedPlanCommitment = (0,
|
|
8706
|
+
const expectedPlanCommitment = (0, import_tool_contract10.publicationCommitment)("plan", {
|
|
8205
8707
|
candidateCommitment,
|
|
8206
8708
|
baseCommitment: plan.baseCommitment,
|
|
8207
8709
|
connectorId,
|
|
@@ -8220,7 +8722,11 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8220
8722
|
}
|
|
8221
8723
|
const toolBlockedReasons = new Set(tools.flatMap((tool) => tool.blockedReasons));
|
|
8222
8724
|
if (tools.some((tool) => !tool.gate.ok) && plan.applyAllowed || tools.some((tool) => tool.opaqueChanged) && (plan.applyAllowed || !blockedReasons.includes("opaque_change")) || TOOL_BLOCKED_REASONS.some(
|
|
8223
|
-
(reason) =>
|
|
8725
|
+
(reason) => (
|
|
8726
|
+
// connector_mismatchはtool単位(既存toolの別connector束縛)に加え、candidateの
|
|
8727
|
+
// upstream.auth.modeとconnector方式の不一致としてtop-levelだけにも出る (#456 / #724)。
|
|
8728
|
+
reason === "connector_mismatch" ? toolBlockedReasons.has(reason) && !blockedReasons.includes(reason) : blockedReasons.includes(reason) !== toolBlockedReasons.has(reason)
|
|
8729
|
+
)
|
|
8224
8730
|
)) {
|
|
8225
8731
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8226
8732
|
}
|
|
@@ -8250,7 +8756,7 @@ function parseToolResults(value, messages) {
|
|
|
8250
8756
|
}
|
|
8251
8757
|
const tools = value.map((candidate) => {
|
|
8252
8758
|
const tool = asRecord4(candidate);
|
|
8253
|
-
if (!tool || !hasExactKeys3(tool, ["toolName", "operation", "toolId", "versionId", "version"]) || !(0,
|
|
8759
|
+
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) {
|
|
8254
8760
|
throw responseInvalid("publication_result_tool_invalid", messages);
|
|
8255
8761
|
}
|
|
8256
8762
|
const operation = tool.operation;
|
|
@@ -8307,7 +8813,7 @@ function parsePublicationResult(value, plan, messages, expectedPublicationId) {
|
|
|
8307
8813
|
function parseConfirmation(value, messages) {
|
|
8308
8814
|
if (value === null) return null;
|
|
8309
8815
|
const confirmation = asRecord4(value);
|
|
8310
|
-
if (!confirmation || !hasExactKeys3(confirmation, ["confirmationId", "signature", "confirmed"]) || !isCanonicalUuid(confirmation.confirmationId) || typeof confirmation.signature !== "string" || !
|
|
8816
|
+
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) {
|
|
8311
8817
|
throw responseInvalid("publication_confirmation_invalid", messages);
|
|
8312
8818
|
}
|
|
8313
8819
|
return {
|
|
@@ -8430,11 +8936,11 @@ function freezeJson(value) {
|
|
|
8430
8936
|
return value;
|
|
8431
8937
|
}
|
|
8432
8938
|
function prepareCandidate(project) {
|
|
8433
|
-
const canonical = (0,
|
|
8939
|
+
const canonical = (0, import_tool_contract10.assertCanonicalPublicationSize)(project.contract.root);
|
|
8434
8940
|
const candidateContract = freezeJson(JSON.parse(canonical));
|
|
8435
8941
|
return {
|
|
8436
8942
|
candidateContract,
|
|
8437
|
-
candidateCommitment: (0,
|
|
8943
|
+
candidateCommitment: (0, import_tool_contract10.publicationCommitment)("candidate", candidateContract)
|
|
8438
8944
|
};
|
|
8439
8945
|
}
|
|
8440
8946
|
function assertIdempotencyKey2(value, messages) {
|
|
@@ -8638,15 +9144,15 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8638
9144
|
);
|
|
8639
9145
|
}
|
|
8640
9146
|
const candidate = prepareCandidate(project);
|
|
8641
|
-
const localToolNames = project.contract.tools.map((tool) => (0,
|
|
8642
|
-
if (localToolNames.some((name) => !(0,
|
|
9147
|
+
const localToolNames = project.contract.tools.map((tool) => (0, import_tool_contract10.toolName)(tool));
|
|
9148
|
+
if (localToolNames.some((name) => !(0, import_tool_contract10.isSafeToolName)(name))) {
|
|
8643
9149
|
throw new PublishCommandError(
|
|
8644
9150
|
"AP_INPUT_INVALID",
|
|
8645
9151
|
"publication_candidate_tool_invalid",
|
|
8646
9152
|
messages.failure("publication_candidate_tool_invalid")
|
|
8647
9153
|
);
|
|
8648
9154
|
}
|
|
8649
|
-
const expectedToolNames = localToolNames.sort(
|
|
9155
|
+
const expectedToolNames = localToolNames.sort(import_tool_contract10.comparePublicationUnicodeCodePoints);
|
|
8650
9156
|
const planRequest = {
|
|
8651
9157
|
environment: "production",
|
|
8652
9158
|
connectorId,
|
|
@@ -8674,6 +9180,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8674
9180
|
messages
|
|
8675
9181
|
);
|
|
8676
9182
|
writePlan(writer, plan);
|
|
9183
|
+
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
9184
|
+
interactive(writer, messages.connectorMismatchRemediation);
|
|
9185
|
+
}
|
|
8677
9186
|
if (normalized.mode === "dry-run") return;
|
|
8678
9187
|
if (!plan.applyAllowed) {
|
|
8679
9188
|
throw new PublishCommandError(
|