@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/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) {
|
|
@@ -3672,6 +3947,41 @@ async function loginAdminCli(input = {}) {
|
|
|
3672
3947
|
}
|
|
3673
3948
|
}
|
|
3674
3949
|
|
|
3950
|
+
// src/lib/open-browser.ts
|
|
3951
|
+
var import_node_child_process = require("child_process");
|
|
3952
|
+
function browserCommandForPlatform(verificationUri, platform = process.platform) {
|
|
3953
|
+
if (platform === "darwin") {
|
|
3954
|
+
return { command: "open", args: [verificationUri] };
|
|
3955
|
+
}
|
|
3956
|
+
if (platform === "win32") {
|
|
3957
|
+
return {
|
|
3958
|
+
command: "rundll32",
|
|
3959
|
+
args: ["url.dll,FileProtocolHandler", verificationUri]
|
|
3960
|
+
};
|
|
3961
|
+
}
|
|
3962
|
+
if (platform === "linux") {
|
|
3963
|
+
return { command: "xdg-open", args: [verificationUri] };
|
|
3964
|
+
}
|
|
3965
|
+
return null;
|
|
3966
|
+
}
|
|
3967
|
+
function openBrowser(verificationUri) {
|
|
3968
|
+
const browserCommand = browserCommandForPlatform(verificationUri);
|
|
3969
|
+
if (!browserCommand) return false;
|
|
3970
|
+
try {
|
|
3971
|
+
const child = (0, import_node_child_process.spawn)(browserCommand.command, [...browserCommand.args], {
|
|
3972
|
+
detached: true,
|
|
3973
|
+
shell: false,
|
|
3974
|
+
stdio: "ignore",
|
|
3975
|
+
windowsHide: true
|
|
3976
|
+
});
|
|
3977
|
+
child.once("error", () => void 0);
|
|
3978
|
+
child.unref();
|
|
3979
|
+
return true;
|
|
3980
|
+
} catch {
|
|
3981
|
+
return false;
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3675
3985
|
// src/commands/auth.ts
|
|
3676
3986
|
function explicitScopes(value) {
|
|
3677
3987
|
if (value === void 0) return void 0;
|
|
@@ -3684,12 +3994,15 @@ function explicitScopes(value) {
|
|
|
3684
3994
|
}
|
|
3685
3995
|
return scopes;
|
|
3686
3996
|
}
|
|
3687
|
-
function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE) {
|
|
3997
|
+
function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE, dependencies = {}) {
|
|
3688
3998
|
const text = import_localization2.LOCALIZED_TEXT[locale].cli;
|
|
3689
3999
|
const messages = import_localization2.CLI_MESSAGES[locale];
|
|
3690
4000
|
program.command("login").description(
|
|
3691
4001
|
locale === "ja" ? "Web Admin\u627F\u8A8D\u3067Admin CLI\u3078\u30ED\u30B0\u30A4\u30F3" : "Sign in to the Admin CLI through Web Admin approval"
|
|
3692
|
-
).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).
|
|
4002
|
+
).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(
|
|
4003
|
+
"--no-browser",
|
|
4004
|
+
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"
|
|
4005
|
+
).action(async (opts) => {
|
|
3693
4006
|
const record = await loginAdminCli({
|
|
3694
4007
|
profile: opts.profile,
|
|
3695
4008
|
requestedScopes: explicitScopes(opts.scope),
|
|
@@ -3698,6 +4011,12 @@ function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOC
|
|
|
3698
4011
|
writer,
|
|
3699
4012
|
locale === "ja" ? `Web Admin\u3067\u627F\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044: ${verificationUri}` : `Approve this request in Web Admin: ${verificationUri}`
|
|
3700
4013
|
);
|
|
4014
|
+
if (opts.browser) {
|
|
4015
|
+
try {
|
|
4016
|
+
(dependencies.openBrowser ?? openBrowser)(verificationUri);
|
|
4017
|
+
} catch {
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
3701
4020
|
},
|
|
3702
4021
|
onUserCode: (userCode) => {
|
|
3703
4022
|
interactive(
|
|
@@ -5408,7 +5727,7 @@ function loadDevProject(cwd, runtime = {}) {
|
|
|
5408
5727
|
}
|
|
5409
5728
|
|
|
5410
5729
|
// src/lib/dev-tunnel.ts
|
|
5411
|
-
var
|
|
5730
|
+
var import_node_child_process2 = require("child_process");
|
|
5412
5731
|
var import_node_fs7 = require("fs");
|
|
5413
5732
|
var import_node_path7 = require("path");
|
|
5414
5733
|
var QUICK_TUNNEL_PROVIDER = "cloudflare-quick";
|
|
@@ -5475,7 +5794,7 @@ async function terminateKnownProcessGroup(pgid, runtime = defaultProcessGroupRun
|
|
|
5475
5794
|
var defaultParentTunnelRuntime = {
|
|
5476
5795
|
...defaultProcessGroupRuntime,
|
|
5477
5796
|
forkSupervisor(modulePath, args, options) {
|
|
5478
|
-
return (0,
|
|
5797
|
+
return (0, import_node_child_process2.fork)(modulePath, [...args], {
|
|
5479
5798
|
detached: options.detached,
|
|
5480
5799
|
execArgv: [...options.execArgv],
|
|
5481
5800
|
stdio: [...options.stdio]
|
|
@@ -5569,7 +5888,7 @@ async function startCloudflareQuickTunnel(input, runtime = defaultParentTunnelRu
|
|
|
5569
5888
|
}
|
|
5570
5889
|
var defaultSupervisorRuntime = {
|
|
5571
5890
|
spawn(file, args, options) {
|
|
5572
|
-
return (0,
|
|
5891
|
+
return (0, import_node_child_process2.spawn)(file, [...args], {
|
|
5573
5892
|
shell: options.shell,
|
|
5574
5893
|
detached: options.detached,
|
|
5575
5894
|
stdio: [...options.stdio]
|
|
@@ -6045,7 +6364,7 @@ var import_node_crypto11 = require("crypto");
|
|
|
6045
6364
|
var import_node_path11 = require("path");
|
|
6046
6365
|
var import_promises2 = require("readline/promises");
|
|
6047
6366
|
var import_localization7 = require("@andpipes/localization");
|
|
6048
|
-
var
|
|
6367
|
+
var import_tool_contract8 = require("@andpipes/tool-contract");
|
|
6049
6368
|
|
|
6050
6369
|
// src/lib/init-manifest.ts
|
|
6051
6370
|
var import_node_fs10 = require("fs");
|
|
@@ -6568,6 +6887,93 @@ function writeInitManifestNoReplace(plan, manifest, runtime) {
|
|
|
6568
6887
|
});
|
|
6569
6888
|
}
|
|
6570
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
|
+
|
|
6571
6977
|
// src/lib/terminal-safe.ts
|
|
6572
6978
|
function isBidirectionalFormatControl(codePoint) {
|
|
6573
6979
|
return codePoint === 1564 || codePoint >= 8206 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297;
|
|
@@ -6604,7 +7010,7 @@ function terminalSafeValue(value) {
|
|
|
6604
7010
|
// src/commands/template.ts
|
|
6605
7011
|
var import_node_crypto10 = require("crypto");
|
|
6606
7012
|
var import_node_path10 = require("path");
|
|
6607
|
-
var
|
|
7013
|
+
var import_tool_contract7 = require("@andpipes/tool-contract");
|
|
6608
7014
|
var BINDINGS_MAX_BYTES = 64 * 1024;
|
|
6609
7015
|
var EXPORT_MAX_BYTES = 1280 * 1024;
|
|
6610
7016
|
var TEMPLATE_ID_RE2 = /^[a-z][a-z0-9._-]{0,63}$/u;
|
|
@@ -6612,7 +7018,7 @@ function createTemplateCommandRuntime(createClient = (profile) => createAdminApi
|
|
|
6612
7018
|
return { createClient, idempotencyKey: import_node_crypto10.randomUUID };
|
|
6613
7019
|
}
|
|
6614
7020
|
function jsonObject(text, label) {
|
|
6615
|
-
const parsed = (0,
|
|
7021
|
+
const parsed = (0, import_tool_contract7.parseToolContract)(text, { format: "json" });
|
|
6616
7022
|
if (!parsed.ok || !parsed.contract || typeof parsed.contract !== "object" || Array.isArray(parsed.contract)) {
|
|
6617
7023
|
throw new UsageError(`${label}\u306Fvalid JSON object\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
|
|
6618
7024
|
}
|
|
@@ -6639,7 +7045,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6639
7045
|
}
|
|
6640
7046
|
let exported;
|
|
6641
7047
|
try {
|
|
6642
|
-
exported = (0,
|
|
7048
|
+
exported = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(source);
|
|
6643
7049
|
} catch {
|
|
6644
7050
|
throw new UsageError("template export artifact\u306Eshape\u304C\u4E0D\u6B63\u3067\u3059");
|
|
6645
7051
|
}
|
|
@@ -6664,7 +7070,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6664
7070
|
}
|
|
6665
7071
|
const bindingSnapshot = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6666
7072
|
const bindingSource = jsonObject(bindingSnapshot.text, "bindings file");
|
|
6667
|
-
const manifest = (0,
|
|
7073
|
+
const manifest = (0, import_tool_contract7.parseExternalSaasTemplate)(source);
|
|
6668
7074
|
const verifiedTemplate = readArtifact(file, EXPORT_MAX_BYTES, "template file");
|
|
6669
7075
|
const verifiedBindings = readArtifact(bindingsFile, BINDINGS_MAX_BYTES, "bindings file");
|
|
6670
7076
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template inputs final root");
|
|
@@ -6676,7 +7082,7 @@ function loadOnboardingTemplateArtifact(cwd, file, bindingsFile) {
|
|
|
6676
7082
|
}
|
|
6677
7083
|
return {
|
|
6678
7084
|
manifest,
|
|
6679
|
-
bindings: (0,
|
|
7085
|
+
bindings: (0, import_tool_contract7.parseOnboardingTemplateBindings)(manifest, bindingSource),
|
|
6680
7086
|
sourceSnapshot: { ...verifiedTemplate.identity, sha256: verifiedTemplate.sha256 }
|
|
6681
7087
|
};
|
|
6682
7088
|
} catch (error) {
|
|
@@ -6705,7 +7111,7 @@ function expectedCurrent(value) {
|
|
|
6705
7111
|
throw new UsageError("--apply\u306B\u306F--expected-current <commitment|none>\u304C\u5FC5\u9808\u3067\u3059");
|
|
6706
7112
|
}
|
|
6707
7113
|
if (value === "none") return null;
|
|
6708
|
-
if (!
|
|
7114
|
+
if (!import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(value)) {
|
|
6709
7115
|
throw new UsageError("--expected-current\u306Fsha256 commitment\u307E\u305F\u306Fnone\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
|
|
6710
7116
|
}
|
|
6711
7117
|
return value;
|
|
@@ -6725,7 +7131,7 @@ function applyProof(options) {
|
|
|
6725
7131
|
"\u5148\u306Bdry-run\u306Esafe diff\u3092\u78BA\u8A8D\u3057\u3001--apply --yes\u3067\u660E\u793A\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044"
|
|
6726
7132
|
);
|
|
6727
7133
|
}
|
|
6728
|
-
if (!options.planCommitment || !
|
|
7134
|
+
if (!options.planCommitment || !import_tool_contract7.EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE.test(options.planCommitment)) {
|
|
6729
7135
|
throw new UsageError("--apply\u306B\u306Fdry-run\u3067\u5F97\u305F--plan-commitment\u304C\u5FC5\u9808\u3067\u3059");
|
|
6730
7136
|
}
|
|
6731
7137
|
return {
|
|
@@ -6734,10 +7140,10 @@ function applyProof(options) {
|
|
|
6734
7140
|
};
|
|
6735
7141
|
}
|
|
6736
7142
|
function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
6737
|
-
const parsedPlan = (0,
|
|
6738
|
-
const templateCommitment = (0,
|
|
6739
|
-
const bindingCommitment = (0,
|
|
6740
|
-
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)({
|
|
6741
7147
|
projectId,
|
|
6742
7148
|
templateCommitment,
|
|
6743
7149
|
bindingCommitment
|
|
@@ -6747,10 +7153,10 @@ function assertPlanMatchesLocal(plan, projectId, loaded) {
|
|
|
6747
7153
|
}
|
|
6748
7154
|
}
|
|
6749
7155
|
function assertApplyMatchesLocal(result, projectId, loaded, planCommitment) {
|
|
6750
|
-
const parsed = (0,
|
|
6751
|
-
const templateCommitment = (0,
|
|
6752
|
-
const bindingCommitment = (0,
|
|
6753
|
-
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)({
|
|
6754
7160
|
projectId,
|
|
6755
7161
|
templateCommitment,
|
|
6756
7162
|
bindingCommitment
|
|
@@ -6800,7 +7206,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6800
7206
|
const client = runtime.createClient(options.profile ?? DEFAULT_PROFILE_NAME);
|
|
6801
7207
|
if (!proof) {
|
|
6802
7208
|
const plan = await client.planOnboardingTemplateRollback(projectId, templateId, targetRevision);
|
|
6803
|
-
const parsed2 = (0,
|
|
7209
|
+
const parsed2 = (0, import_tool_contract7.parseOnboardingTemplateSafePlanDto)(plan);
|
|
6804
7210
|
if (parsed2.projectId !== projectId || parsed2.templateId !== templateId || parsed2.operation !== "rollback" || parsed2.rollbackFromRevision !== targetRevision || parsed2.currentApplicationCommitment === null) {
|
|
6805
7211
|
throw new UsageError("Admin API\u306Erollback plan\u304C\u8981\u6C42scope\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6806
7212
|
}
|
|
@@ -6831,7 +7237,7 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
6831
7237
|
confirmed: true
|
|
6832
7238
|
}
|
|
6833
7239
|
);
|
|
6834
|
-
const parsed = (0,
|
|
7240
|
+
const parsed = (0, import_tool_contract7.parseOnboardingTemplateApplyDto)(result);
|
|
6835
7241
|
if (parsed.projectId !== projectId || parsed.templateId !== templateId || parsed.operation !== "rollback" || parsed.rollbackFromRevision !== targetRevision || parsed.planCommitment !== proof.planCommitment || parsed.applicationCommitment === proof.expectedCurrent) {
|
|
6836
7242
|
throw new UsageError("Admin API\u306Erollback\u7D50\u679C\u304C\u78BA\u8A8D\u6E08\u307F\u8A08\u753B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
6837
7243
|
}
|
|
@@ -6848,8 +7254,8 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
6848
7254
|
valid: true,
|
|
6849
7255
|
templateId: loaded.manifest.templateId,
|
|
6850
7256
|
templateVersion: loaded.manifest.version,
|
|
6851
|
-
templateCommitment: (0,
|
|
6852
|
-
bindingCommitment: (0,
|
|
7257
|
+
templateCommitment: (0, import_tool_contract7.externalSaasTemplateCommitment)(loaded.manifest),
|
|
7258
|
+
bindingCommitment: (0, import_tool_contract7.onboardingTemplateBindingCommitment)(loaded.bindings),
|
|
6853
7259
|
...loaded.exportApplicationCommitment ? { applicationCommitment: loaded.exportApplicationCommitment } : {}
|
|
6854
7260
|
});
|
|
6855
7261
|
});
|
|
@@ -6868,7 +7274,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
6868
7274
|
const projectId = assertProjectId(options.project);
|
|
6869
7275
|
const templateId = canonicalTemplateId(options.template);
|
|
6870
7276
|
const anchor = captureLocalRootPath(cwd());
|
|
6871
|
-
const result = (0,
|
|
7277
|
+
const result = (0, import_tool_contract7.parseOnboardingTemplateExportDto)(
|
|
6872
7278
|
await runtime.createClient(options.profile).exportOnboardingTemplate(projectId, templateId)
|
|
6873
7279
|
);
|
|
6874
7280
|
if (result.projectId !== projectId || result.manifest.templateId !== templateId) {
|
|
@@ -6924,8 +7330,13 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
6924
7330
|
if (options.openapi !== void 0 && options.project === void 0) {
|
|
6925
7331
|
throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
|
|
6926
7332
|
}
|
|
6927
|
-
if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
|
|
6928
|
-
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
|
+
);
|
|
6929
7340
|
}
|
|
6930
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)) {
|
|
6931
7342
|
throw new UsageError(
|
|
@@ -6950,26 +7361,36 @@ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES
|
|
|
6950
7361
|
}
|
|
6951
7362
|
}
|
|
6952
7363
|
async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
6953
|
-
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);
|
|
6954
7367
|
const contractPath = "tool-contract.json";
|
|
6955
7368
|
prepareLocalOrThrow(runtime, anchor, contractPath, messages);
|
|
6956
7369
|
const source = withAnchoredLocalRoot(
|
|
6957
7370
|
anchor.root,
|
|
6958
7371
|
anchor.rootIdentity,
|
|
6959
7372
|
() => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
|
|
6960
|
-
maxBytes:
|
|
7373
|
+
maxBytes: import_tool_contract8.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
6961
7374
|
root: anchor.root
|
|
6962
7375
|
})
|
|
6963
7376
|
);
|
|
6964
7377
|
let imported;
|
|
6965
7378
|
try {
|
|
6966
|
-
|
|
7379
|
+
const importOptions = {
|
|
6967
7380
|
...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
|
|
6968
7381
|
...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
|
|
6969
|
-
...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
|
|
6970
|
-
|
|
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
|
+
}
|
|
6971
7392
|
} catch (error) {
|
|
6972
|
-
if (error instanceof
|
|
7393
|
+
if (error instanceof import_tool_contract8.OpenApiImportError) {
|
|
6973
7394
|
throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
|
|
6974
7395
|
}
|
|
6975
7396
|
throw error;
|
|
@@ -7014,13 +7435,27 @@ async function materializeOpenApiInit(options, anchor, runtime, messages) {
|
|
|
7014
7435
|
messages.failure("local_file_changed")
|
|
7015
7436
|
);
|
|
7016
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
|
+
}
|
|
7017
7451
|
return {
|
|
7018
7452
|
options: {
|
|
7019
7453
|
project: options.project,
|
|
7020
7454
|
contract: contractPath,
|
|
7021
7455
|
profile: options.profile
|
|
7022
7456
|
},
|
|
7023
|
-
anchor: refreshedAnchor
|
|
7457
|
+
anchor: refreshedAnchor,
|
|
7458
|
+
notices
|
|
7024
7459
|
};
|
|
7025
7460
|
}
|
|
7026
7461
|
async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
@@ -7073,7 +7508,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7073
7508
|
contractPath,
|
|
7074
7509
|
anchor.root,
|
|
7075
7510
|
contractText,
|
|
7076
|
-
|
|
7511
|
+
import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7077
7512
|
{ expectedRootIdentity: anchor.rootIdentity }
|
|
7078
7513
|
);
|
|
7079
7514
|
} catch (error) {
|
|
@@ -7081,7 +7516,7 @@ async function materializeTemplateInit(options, anchor, runtime, messages) {
|
|
|
7081
7516
|
try {
|
|
7082
7517
|
assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "template contract fallback");
|
|
7083
7518
|
const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
|
|
7084
|
-
maxBytes:
|
|
7519
|
+
maxBytes: import_tool_contract8.EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
|
|
7085
7520
|
root: anchor.root,
|
|
7086
7521
|
directChildOnly: true
|
|
7087
7522
|
});
|
|
@@ -7542,6 +7977,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7542
7977
|
const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
|
|
7543
7978
|
rootAnchor = materialized.anchor;
|
|
7544
7979
|
mode = normalizeInitOptions(materialized.options, messages);
|
|
7980
|
+
for (const notice of materialized.notices) interactive(writer, notice);
|
|
7545
7981
|
}
|
|
7546
7982
|
if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
|
|
7547
7983
|
let actionMode;
|
|
@@ -7617,7 +8053,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7617
8053
|
idempotencyKey: actionMode.connectorCreate.idempotencyKey,
|
|
7618
8054
|
connector: actionMode.connectorCreate.input
|
|
7619
8055
|
});
|
|
7620
|
-
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)) {
|
|
7621
8057
|
throw new InitCommandError(
|
|
7622
8058
|
"AP_RESPONSE_INVALID",
|
|
7623
8059
|
"template_connector_create_mismatch",
|
|
@@ -7645,6 +8081,14 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
|
|
|
7645
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) {
|
|
7646
8082
|
const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
|
|
7647
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(
|
|
7648
8092
|
"--create-connector",
|
|
7649
8093
|
"Create the template connector through the existing Admin API policy boundary",
|
|
7650
8094
|
false
|
|
@@ -7752,6 +8196,14 @@ function buildInitTemplate(provider) {
|
|
|
7752
8196
|
scopes: ["openid", "profile"]
|
|
7753
8197
|
};
|
|
7754
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
|
+
}
|
|
7755
8207
|
async function loadOAuthMetadata(opts, locale) {
|
|
7756
8208
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7757
8209
|
if (opts.file && opts.issuer) {
|
|
@@ -7781,7 +8233,7 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
7781
8233
|
info(writer, messages.oauth.metadataOk);
|
|
7782
8234
|
}
|
|
7783
8235
|
}
|
|
7784
|
-
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE) {
|
|
8236
|
+
function registerOauth(program, writer, locale = import_localization9.DEFAULT_LOCALE, dependencies = {}) {
|
|
7785
8237
|
const messages = import_localization9.CLI_MESSAGES[locale];
|
|
7786
8238
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
7787
8239
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
@@ -7862,6 +8314,43 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
7862
8314
|
metadata.command("validate").description(messages.oauth.validateDescription).option("--file <path>", messages.common.metadataFileOption).option("--issuer <url>", messages.common.issuerOption).action(async (opts) => {
|
|
7863
8315
|
await runOAuthMetadataValidate(opts, writer, locale);
|
|
7864
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
|
+
);
|
|
7865
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) => {
|
|
7866
8355
|
const projectId = assertProjectId(opts.project);
|
|
7867
8356
|
const result = await createAdminApiClient({ profile: opts.profile }).testOAuthLogin(
|
|
@@ -7876,7 +8365,7 @@ function registerOauth(program, writer, locale = import_localization9.DEFAULT_LO
|
|
|
7876
8365
|
// src/commands/openapi.ts
|
|
7877
8366
|
var import_node_crypto12 = require("crypto");
|
|
7878
8367
|
var import_node_path12 = require("path");
|
|
7879
|
-
var
|
|
8368
|
+
var import_tool_contract9 = require("@andpipes/tool-contract");
|
|
7880
8369
|
function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
7881
8370
|
return { createClient, idempotencyKey: import_node_crypto12.randomUUID };
|
|
7882
8371
|
}
|
|
@@ -7912,9 +8401,17 @@ function normalizedOptions(options) {
|
|
|
7912
8401
|
apply,
|
|
7913
8402
|
yes,
|
|
7914
8403
|
...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
|
|
7915
|
-
...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)
|
|
7916
8407
|
};
|
|
7917
8408
|
}
|
|
8409
|
+
function rethrowWithAuthModeGuidance(error) {
|
|
8410
|
+
if (error instanceof AdminApiClientError && error.openApiAuthModeMismatch) {
|
|
8411
|
+
throw new UsageError(authModeMismatchGuidance(error.openApiAuthModeMismatch));
|
|
8412
|
+
}
|
|
8413
|
+
throw error;
|
|
8414
|
+
}
|
|
7918
8415
|
async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
7919
8416
|
const normalized = normalizedOptions(options);
|
|
7920
8417
|
if (normalized.apply && !normalized.yes) {
|
|
@@ -7927,39 +8424,88 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
7927
8424
|
throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
|
|
7928
8425
|
}
|
|
7929
8426
|
const snapshot = readBoundedLocalFileSnapshot((0, import_node_path12.resolve)(cwd, normalized.file), {
|
|
7930
|
-
maxBytes:
|
|
8427
|
+
maxBytes: import_tool_contract9.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
|
|
7931
8428
|
root: cwd
|
|
7932
8429
|
});
|
|
7933
|
-
const
|
|
8430
|
+
const baseRequest = {
|
|
7934
8431
|
source: snapshot.text,
|
|
7935
8432
|
connectorId: normalized.connectorId,
|
|
7936
8433
|
...normalized.format !== void 0 ? { format: normalized.format } : {},
|
|
7937
8434
|
...normalized.baseUrl !== void 0 ? { baseUrl: normalized.baseUrl } : {},
|
|
7938
8435
|
...normalized.serviceName !== void 0 ? { serviceName: normalized.serviceName } : {},
|
|
7939
|
-
...normalized.
|
|
8436
|
+
...normalized.upstreamAuthMode !== void 0 ? { upstreamAuthMode: normalized.upstreamAuthMode } : {}
|
|
7940
8437
|
};
|
|
7941
8438
|
const client = runtime.createClient(normalized.profile);
|
|
7942
|
-
|
|
7943
|
-
|
|
7944
|
-
if (result2.sourceCommitment !== snapshot.sha256) {
|
|
8439
|
+
const assertSource = (sourceCommitment) => {
|
|
8440
|
+
if (sourceCommitment !== snapshot.sha256) {
|
|
7945
8441
|
throw new UsageError("Admin API\u306Esource commitment\u304Clocal file\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
7946
8442
|
}
|
|
7947
|
-
|
|
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);
|
|
7948
8485
|
return;
|
|
7949
8486
|
}
|
|
7950
8487
|
const result = await client.applyOpenApiImport(
|
|
7951
8488
|
normalized.project,
|
|
7952
8489
|
normalized.idempotencyKey ?? runtime.idempotencyKey(),
|
|
7953
8490
|
request
|
|
7954
|
-
);
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
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];
|
|
7959
8497
|
}
|
|
7960
8498
|
function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRuntime()) {
|
|
7961
8499
|
const openapi = program.command("openapi").description("OpenAPI\u304B\u3089Tool Contract draft\u3092\u63D0\u6848\u3059\u308B");
|
|
7962
|
-
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(
|
|
7963
8509
|
(options) => runOpenApiImportCommand(options, writer, cwd(), runtime)
|
|
7964
8510
|
);
|
|
7965
8511
|
}
|
|
@@ -7967,7 +8513,7 @@ function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRunt
|
|
|
7967
8513
|
// src/commands/publish.ts
|
|
7968
8514
|
var import_node_crypto13 = require("crypto");
|
|
7969
8515
|
var import_localization10 = require("@andpipes/localization");
|
|
7970
|
-
var
|
|
8516
|
+
var import_tool_contract10 = require("@andpipes/tool-contract");
|
|
7971
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;
|
|
7972
8518
|
var SAFE_AP_CODE_RE2 = /^AP_[A-Z0-9_]{1,64}$/u;
|
|
7973
8519
|
var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
@@ -8104,7 +8650,7 @@ function responseInvalid(reason, messages) {
|
|
|
8104
8650
|
}
|
|
8105
8651
|
function assertCanonicalResponseSize(value, reason, messages, maxBytes = PUBLICATION_RESPONSE_MAX_BYTES) {
|
|
8106
8652
|
try {
|
|
8107
|
-
(0,
|
|
8653
|
+
(0, import_tool_contract10.assertCanonicalPublicationSize)(value, maxBytes);
|
|
8108
8654
|
} catch {
|
|
8109
8655
|
throw responseInvalid(reason, messages);
|
|
8110
8656
|
}
|
|
@@ -8113,7 +8659,7 @@ function isCanonicalUuid(value) {
|
|
|
8113
8659
|
return typeof value === "string" && UUID_RE6.test(value);
|
|
8114
8660
|
}
|
|
8115
8661
|
function isCommitment(value) {
|
|
8116
|
-
return typeof value === "string" &&
|
|
8662
|
+
return typeof value === "string" && import_tool_contract10.PUBLICATION_SHA256_COMMITMENT_RE.test(value);
|
|
8117
8663
|
}
|
|
8118
8664
|
function isCanonicalTimestamp(value) {
|
|
8119
8665
|
if (typeof value !== "string" || value.length > 64) return false;
|
|
@@ -8122,12 +8668,12 @@ function isCanonicalTimestamp(value) {
|
|
|
8122
8668
|
}
|
|
8123
8669
|
function isStrictlySorted(values) {
|
|
8124
8670
|
return values.every(
|
|
8125
|
-
(value, index) => index === 0 || (0,
|
|
8671
|
+
(value, index) => index === 0 || (0, import_tool_contract10.comparePublicationUnicodeCodePoints)(values[index - 1], value) < 0
|
|
8126
8672
|
);
|
|
8127
8673
|
}
|
|
8128
8674
|
function parseWarnings(value, messages) {
|
|
8129
8675
|
try {
|
|
8130
|
-
return (0,
|
|
8676
|
+
return (0, import_tool_contract10.parsePublicationWarningsDto)(value);
|
|
8131
8677
|
} catch {
|
|
8132
8678
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8133
8679
|
}
|
|
@@ -8143,7 +8689,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8143
8689
|
const blockedReasons = plan.blockedReasons;
|
|
8144
8690
|
let safeDiff;
|
|
8145
8691
|
try {
|
|
8146
|
-
safeDiff = (0,
|
|
8692
|
+
safeDiff = (0, import_tool_contract10.parsePublicationSafeDiffDto)({
|
|
8147
8693
|
tools: plan.tools,
|
|
8148
8694
|
retainedTools: plan.retainedTools,
|
|
8149
8695
|
warnings: plan.warnings
|
|
@@ -8157,7 +8703,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8157
8703
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8158
8704
|
}
|
|
8159
8705
|
const warnings = safeDiff.warnings;
|
|
8160
|
-
const expectedPlanCommitment = (0,
|
|
8706
|
+
const expectedPlanCommitment = (0, import_tool_contract10.publicationCommitment)("plan", {
|
|
8161
8707
|
candidateCommitment,
|
|
8162
8708
|
baseCommitment: plan.baseCommitment,
|
|
8163
8709
|
connectorId,
|
|
@@ -8176,7 +8722,11 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8176
8722
|
}
|
|
8177
8723
|
const toolBlockedReasons = new Set(tools.flatMap((tool) => tool.blockedReasons));
|
|
8178
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(
|
|
8179
|
-
(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
|
+
)
|
|
8180
8730
|
)) {
|
|
8181
8731
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8182
8732
|
}
|
|
@@ -8206,7 +8756,7 @@ function parseToolResults(value, messages) {
|
|
|
8206
8756
|
}
|
|
8207
8757
|
const tools = value.map((candidate) => {
|
|
8208
8758
|
const tool = asRecord4(candidate);
|
|
8209
|
-
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) {
|
|
8210
8760
|
throw responseInvalid("publication_result_tool_invalid", messages);
|
|
8211
8761
|
}
|
|
8212
8762
|
const operation = tool.operation;
|
|
@@ -8263,7 +8813,7 @@ function parsePublicationResult(value, plan, messages, expectedPublicationId) {
|
|
|
8263
8813
|
function parseConfirmation(value, messages) {
|
|
8264
8814
|
if (value === null) return null;
|
|
8265
8815
|
const confirmation = asRecord4(value);
|
|
8266
|
-
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) {
|
|
8267
8817
|
throw responseInvalid("publication_confirmation_invalid", messages);
|
|
8268
8818
|
}
|
|
8269
8819
|
return {
|
|
@@ -8386,11 +8936,11 @@ function freezeJson(value) {
|
|
|
8386
8936
|
return value;
|
|
8387
8937
|
}
|
|
8388
8938
|
function prepareCandidate(project) {
|
|
8389
|
-
const canonical = (0,
|
|
8939
|
+
const canonical = (0, import_tool_contract10.assertCanonicalPublicationSize)(project.contract.root);
|
|
8390
8940
|
const candidateContract = freezeJson(JSON.parse(canonical));
|
|
8391
8941
|
return {
|
|
8392
8942
|
candidateContract,
|
|
8393
|
-
candidateCommitment: (0,
|
|
8943
|
+
candidateCommitment: (0, import_tool_contract10.publicationCommitment)("candidate", candidateContract)
|
|
8394
8944
|
};
|
|
8395
8945
|
}
|
|
8396
8946
|
function assertIdempotencyKey2(value, messages) {
|
|
@@ -8594,15 +9144,15 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8594
9144
|
);
|
|
8595
9145
|
}
|
|
8596
9146
|
const candidate = prepareCandidate(project);
|
|
8597
|
-
const localToolNames = project.contract.tools.map((tool) => (0,
|
|
8598
|
-
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))) {
|
|
8599
9149
|
throw new PublishCommandError(
|
|
8600
9150
|
"AP_INPUT_INVALID",
|
|
8601
9151
|
"publication_candidate_tool_invalid",
|
|
8602
9152
|
messages.failure("publication_candidate_tool_invalid")
|
|
8603
9153
|
);
|
|
8604
9154
|
}
|
|
8605
|
-
const expectedToolNames = localToolNames.sort(
|
|
9155
|
+
const expectedToolNames = localToolNames.sort(import_tool_contract10.comparePublicationUnicodeCodePoints);
|
|
8606
9156
|
const planRequest = {
|
|
8607
9157
|
environment: "production",
|
|
8608
9158
|
connectorId,
|
|
@@ -8630,6 +9180,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8630
9180
|
messages
|
|
8631
9181
|
);
|
|
8632
9182
|
writePlan(writer, plan);
|
|
9183
|
+
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
9184
|
+
interactive(writer, messages.connectorMismatchRemediation);
|
|
9185
|
+
}
|
|
8633
9186
|
if (normalized.mode === "dry-run") return;
|
|
8634
9187
|
if (!plan.applyAllowed) {
|
|
8635
9188
|
throw new PublishCommandError(
|