@andpipes/cli 0.1.4 → 0.1.5
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/dist/bin.cjs +212 -29
- package/dist/bin.js +1 -1
- package/dist/{chunk-VFSDVWMN.js → chunk-2PG5NEI2.js} +218 -31
- package/dist/index.cjs +212 -29
- package/dist/index.d.cts +63 -7
- package/dist/index.d.ts +63 -7
- package/dist/index.js +1 -1
- package/package.json +4 -4
|
@@ -35,7 +35,8 @@ import {
|
|
|
35
35
|
DEFAULT_LOCALE as DEFAULT_LOCALE10,
|
|
36
36
|
LOCALIZED_TEXT as LOCALIZED_TEXT4,
|
|
37
37
|
normalizeLocale,
|
|
38
|
-
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES4
|
|
38
|
+
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES4,
|
|
39
|
+
PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES as PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES2
|
|
39
40
|
} from "@andpipes/localization";
|
|
40
41
|
import { Command } from "commander";
|
|
41
42
|
|
|
@@ -64,6 +65,7 @@ import {
|
|
|
64
65
|
onboardingTemplateApplicationCommitment,
|
|
65
66
|
onboardingTemplateBindingCommitment,
|
|
66
67
|
PUBLICATION_CONFIRMATION_SIGNATURE_RE,
|
|
68
|
+
PUBLICATION_REVIEW_PROFILE_HEADER,
|
|
67
69
|
PUBLICATION_SHA256_COMMITMENT_RE,
|
|
68
70
|
parseExternalSaasTemplate,
|
|
69
71
|
parseOAuthScopeRegistrationResponse,
|
|
@@ -550,6 +552,26 @@ var ConfirmationRequiredError = class extends Error {
|
|
|
550
552
|
}
|
|
551
553
|
};
|
|
552
554
|
|
|
555
|
+
// src/lib/publication-review-profile.ts
|
|
556
|
+
var CLI_PUBLICATION_REVIEW_PROFILE = 2;
|
|
557
|
+
var PUBLICATION_ERROR_REASON_CODES = Object.freeze({
|
|
558
|
+
publication_plan_stale: "AP_CONFLICT",
|
|
559
|
+
publication_review_profile_invalid: "AP_INPUT_INVALID",
|
|
560
|
+
publication_schema_review_too_large: "AP_INPUT_INVALID",
|
|
561
|
+
schema_review_receipt_mismatch: "AP_CONFLICT"
|
|
562
|
+
});
|
|
563
|
+
function isPublicationErrorReasonFor(code, reason) {
|
|
564
|
+
return typeof reason === "string" && Object.hasOwn(PUBLICATION_ERROR_REASON_CODES, reason) && PUBLICATION_ERROR_REASON_CODES[reason] === code;
|
|
565
|
+
}
|
|
566
|
+
function parsePublicationErrorReason(status, code, details) {
|
|
567
|
+
if (status < 400 || status > 499) return void 0;
|
|
568
|
+
if (details === null || typeof details !== "object" || Array.isArray(details)) return void 0;
|
|
569
|
+
const record = details;
|
|
570
|
+
const keys = Object.keys(record);
|
|
571
|
+
if (keys.length !== 1 || keys[0] !== "reason") return void 0;
|
|
572
|
+
return isPublicationErrorReasonFor(code, record.reason) ? record.reason : void 0;
|
|
573
|
+
}
|
|
574
|
+
|
|
553
575
|
// src/lib/backend.ts
|
|
554
576
|
var ADMIN_API_ORIGIN = "https://api.andpipe.com";
|
|
555
577
|
var ADMIN_API_TIMEOUT_MS = 1e4;
|
|
@@ -579,6 +601,7 @@ var AdminApiClientError = class extends Error {
|
|
|
579
601
|
detailsAbsent;
|
|
580
602
|
scopeRegistrationReason;
|
|
581
603
|
publishGateToolNames;
|
|
604
|
+
publicationReason;
|
|
582
605
|
constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch, safeDetails = {}) {
|
|
583
606
|
super(message);
|
|
584
607
|
this.name = "AdminApiClientError";
|
|
@@ -589,6 +612,7 @@ var AdminApiClientError = class extends Error {
|
|
|
589
612
|
this.detailsAbsent = safeDetails.detailsAbsent === true;
|
|
590
613
|
this.scopeRegistrationReason = safeDetails.scopeRegistrationReason;
|
|
591
614
|
this.publishGateToolNames = safeDetails.publishGateToolNames === void 0 ? void 0 : Object.freeze([...safeDetails.publishGateToolNames]);
|
|
615
|
+
this.publicationReason = safeDetails.publicationReason;
|
|
592
616
|
}
|
|
593
617
|
};
|
|
594
618
|
function clientError(code, message, status) {
|
|
@@ -803,7 +827,8 @@ function withKnownResponseStatus(error, responseStatus) {
|
|
|
803
827
|
{
|
|
804
828
|
detailsAbsent: error.detailsAbsent,
|
|
805
829
|
...error.scopeRegistrationReason === void 0 ? {} : { scopeRegistrationReason: error.scopeRegistrationReason },
|
|
806
|
-
...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames }
|
|
830
|
+
...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames },
|
|
831
|
+
...error.publicationReason === void 0 ? {} : { publicationReason: error.publicationReason }
|
|
807
832
|
}
|
|
808
833
|
);
|
|
809
834
|
}
|
|
@@ -872,6 +897,7 @@ function safeApiError(status, value) {
|
|
|
872
897
|
const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
|
|
873
898
|
const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
|
|
874
899
|
const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
|
|
900
|
+
const publicationReason = parsePublicationErrorReason(status, code, errorRecord?.details);
|
|
875
901
|
return new AdminApiClientError(
|
|
876
902
|
code,
|
|
877
903
|
`Admin API request failed (${code}; HTTP ${status})`,
|
|
@@ -881,7 +907,8 @@ function safeApiError(status, value) {
|
|
|
881
907
|
{
|
|
882
908
|
// AP error envelopeを受け取れた場合だけ「detailsなし」を判定できる。
|
|
883
909
|
detailsAbsent: errorRecord !== void 0 && (errorRecord.details === null || errorRecord.details === void 0),
|
|
884
|
-
...parseScopeRegistrationErrorDetails(status, errorRecord?.details)
|
|
910
|
+
...parseScopeRegistrationErrorDetails(status, errorRecord?.details),
|
|
911
|
+
...publicationReason === void 0 ? {} : { publicationReason }
|
|
885
912
|
}
|
|
886
913
|
);
|
|
887
914
|
}
|
|
@@ -1015,6 +1042,13 @@ function publicationPlanBody(input) {
|
|
|
1015
1042
|
...input.templateProvenance === void 0 ? {} : { templateProvenance: input.templateProvenance }
|
|
1016
1043
|
};
|
|
1017
1044
|
}
|
|
1045
|
+
function publicationReviewProfileOption(options) {
|
|
1046
|
+
if (options === void 0) return void 0;
|
|
1047
|
+
if (options === null || typeof options !== "object" || Object.keys(options).join(",") !== "reviewProfile" || options.reviewProfile !== 2) {
|
|
1048
|
+
throw clientError("AP_INPUT_INVALID", "tool publication review profile option is invalid");
|
|
1049
|
+
}
|
|
1050
|
+
return options.reviewProfile;
|
|
1051
|
+
}
|
|
1018
1052
|
function publicationApplyBody(input) {
|
|
1019
1053
|
const common = publicationPlanBody(input);
|
|
1020
1054
|
if (!PUBLICATION_SHA256_COMMITMENT_RE.test(input.planCommitment)) {
|
|
@@ -1370,6 +1404,10 @@ var AdminApiClient = class {
|
|
|
1370
1404
|
this.#sleep = options.sleep ?? ((milliseconds) => new Promise((resolve6) => setTimeout(resolve6, milliseconds)));
|
|
1371
1405
|
}
|
|
1372
1406
|
async #request(path, options = {}) {
|
|
1407
|
+
return (await this.#requestWithHeaders(path, options)).value;
|
|
1408
|
+
}
|
|
1409
|
+
/** 2xx bodyと、そのresponse headerを返す。headerはcommand層が必要な値だけを読む。 */
|
|
1410
|
+
async #requestWithHeaders(path, options = {}) {
|
|
1373
1411
|
const url = buildUrl(path);
|
|
1374
1412
|
const method = options.method ?? "GET";
|
|
1375
1413
|
const attempts = method === "GET" ? ADMIN_API_MAX_GET_ATTEMPTS : 1;
|
|
@@ -1391,6 +1429,9 @@ var AdminApiClient = class {
|
|
|
1391
1429
|
if (options.authenticated !== false) headers.set("Authorization", `Bearer ${this.#token}`);
|
|
1392
1430
|
if (body !== void 0) headers.set("Content-Type", "application/json");
|
|
1393
1431
|
if (options.idempotencyKey) headers.set("Idempotency-Key", options.idempotencyKey);
|
|
1432
|
+
if (options.reviewProfile !== void 0) {
|
|
1433
|
+
headers.set(PUBLICATION_REVIEW_PROFILE_HEADER, String(options.reviewProfile));
|
|
1434
|
+
}
|
|
1394
1435
|
response = await this.#fetch(url, {
|
|
1395
1436
|
method,
|
|
1396
1437
|
headers,
|
|
@@ -1447,8 +1488,8 @@ var AdminApiClient = class {
|
|
|
1447
1488
|
}
|
|
1448
1489
|
throw safeApiError(response.status, errorBody);
|
|
1449
1490
|
}
|
|
1450
|
-
if (options.responseType === "text") return text;
|
|
1451
|
-
return parseJson(text);
|
|
1491
|
+
if (options.responseType === "text") return { value: text, headers: response.headers };
|
|
1492
|
+
return { value: parseJson(text), headers: response.headers };
|
|
1452
1493
|
}
|
|
1453
1494
|
throw clientError("AP_NETWORK_ERROR", "Admin API request failed");
|
|
1454
1495
|
}
|
|
@@ -1594,24 +1635,41 @@ var AdminApiClient = class {
|
|
|
1594
1635
|
status: connector.status
|
|
1595
1636
|
};
|
|
1596
1637
|
}
|
|
1597
|
-
async planPublication(projectId, body) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1638
|
+
async planPublication(projectId, body, options) {
|
|
1639
|
+
const reviewProfile = publicationReviewProfileOption(options);
|
|
1640
|
+
const response = await this.#requestWithHeaders(
|
|
1641
|
+
`/v1/projects/${assertProjectId(projectId)}/tool-publications:plan`,
|
|
1642
|
+
{
|
|
1643
|
+
method: "POST",
|
|
1644
|
+
body: publicationPlanBody(body),
|
|
1645
|
+
maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
|
|
1646
|
+
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
|
|
1647
|
+
...reviewProfile === void 0 ? {} : { reviewProfile }
|
|
1648
|
+
}
|
|
1649
|
+
);
|
|
1650
|
+
if (reviewProfile === void 0) return response.value;
|
|
1651
|
+
const planResponse = {
|
|
1652
|
+
body: response.value,
|
|
1653
|
+
reviewProfileHeader: response.headers.get(PUBLICATION_REVIEW_PROFILE_HEADER)
|
|
1654
|
+
};
|
|
1655
|
+
return planResponse;
|
|
1604
1656
|
}
|
|
1605
|
-
|
|
1657
|
+
/**
|
|
1658
|
+
* 初回apply(confirmation=null)と承認済みapply。options付き (#730) だけreview profile headerを送る。
|
|
1659
|
+
* request bodyとIdempotency-Keyはheaderの有無で変えない。
|
|
1660
|
+
*/
|
|
1661
|
+
async applyPublication(projectId, idempotencyKey, body, options) {
|
|
1606
1662
|
if (!/^[A-Za-z0-9._:-]{22,200}$/u.test(idempotencyKey)) {
|
|
1607
1663
|
throw clientError("AP_INPUT_INVALID", "tool publication Idempotency-Key is invalid");
|
|
1608
1664
|
}
|
|
1665
|
+
const reviewProfile = publicationReviewProfileOption(options);
|
|
1609
1666
|
return this.#request(`/v1/projects/${assertProjectId(projectId)}/tool-publications`, {
|
|
1610
1667
|
method: "POST",
|
|
1611
1668
|
body: publicationApplyBody(body),
|
|
1612
1669
|
idempotencyKey,
|
|
1613
1670
|
maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
|
|
1614
|
-
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES
|
|
1671
|
+
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
|
|
1672
|
+
...reviewProfile === void 0 ? {} : { reviewProfile }
|
|
1615
1673
|
});
|
|
1616
1674
|
}
|
|
1617
1675
|
async planOpenApiImport(projectId, input) {
|
|
@@ -7862,7 +7920,8 @@ import {
|
|
|
7862
7920
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
7863
7921
|
import {
|
|
7864
7922
|
CLI_MESSAGES as CLI_MESSAGES8,
|
|
7865
|
-
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES2
|
|
7923
|
+
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES2,
|
|
7924
|
+
PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES
|
|
7866
7925
|
} from "@andpipes/localization";
|
|
7867
7926
|
import {
|
|
7868
7927
|
assertCanonicalPublicationSize as assertCanonicalPublicationSize2,
|
|
@@ -7873,6 +7932,7 @@ import {
|
|
|
7873
7932
|
parsePublicationSafeDiffDto,
|
|
7874
7933
|
parsePublicationWarningsDto,
|
|
7875
7934
|
publicationCommitment as publicationCommitment2,
|
|
7935
|
+
selectPublicationReviewProfile,
|
|
7876
7936
|
toolName as toolName2
|
|
7877
7937
|
} from "@andpipes/tool-contract";
|
|
7878
7938
|
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;
|
|
@@ -7881,6 +7941,10 @@ var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
|
7881
7941
|
var INITIAL_APPLY_MAX_ATTEMPTS = 3;
|
|
7882
7942
|
var DEFAULT_PUBLISH_MESSAGES = CLI_MESSAGES8.ja.publish;
|
|
7883
7943
|
var DEFAULT_SCOPE_REGISTRATION_MESSAGES2 = OAUTH_SCOPE_REGISTRATION_MESSAGES2.ja.cli;
|
|
7944
|
+
var DEFAULT_SCHEMA_REVIEW_MESSAGES = PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES.ja;
|
|
7945
|
+
var REVIEW_PROFILE_REQUEST = Object.freeze({
|
|
7946
|
+
reviewProfile: CLI_PUBLICATION_REVIEW_PROFILE
|
|
7947
|
+
});
|
|
7884
7948
|
var PLAN_KEYS = [
|
|
7885
7949
|
"requestId",
|
|
7886
7950
|
"environment",
|
|
@@ -8040,10 +8104,41 @@ function parseWarnings(value, messages) {
|
|
|
8040
8104
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8041
8105
|
}
|
|
8042
8106
|
}
|
|
8043
|
-
function
|
|
8107
|
+
function schemaReviewFailure(code, reason, text, status) {
|
|
8108
|
+
return new PublishCommandError(code, reason, `${text} (${reason})`, status);
|
|
8109
|
+
}
|
|
8110
|
+
function negotiateReviewProfile(response, messages, schemaReviewMessages) {
|
|
8111
|
+
const envelope = asRecord4(response);
|
|
8112
|
+
if (!envelope || !hasExactKeys3(envelope, ["body", "reviewProfileHeader"]) || envelope.reviewProfileHeader !== null && typeof envelope.reviewProfileHeader !== "string") {
|
|
8113
|
+
throw responseInvalid("publication_plan_invalid", messages);
|
|
8114
|
+
}
|
|
8115
|
+
const header = envelope.reviewProfileHeader;
|
|
8116
|
+
if (header !== null && header !== "1" && header !== "2") {
|
|
8117
|
+
throw schemaReviewFailure(
|
|
8118
|
+
"AP_RESPONSE_INVALID",
|
|
8119
|
+
"publication_review_profile_header_invalid",
|
|
8120
|
+
schemaReviewMessages.reviewProfileHeaderInvalid
|
|
8121
|
+
);
|
|
8122
|
+
}
|
|
8123
|
+
const body = asRecord4(envelope.body);
|
|
8124
|
+
const bodyDeclaresProfile = body !== null && Object.hasOwn(body, "reviewProfile");
|
|
8125
|
+
const profile = header === "2" ? 2 : 1;
|
|
8126
|
+
if (profile === 2 ? !bodyDeclaresProfile || body?.reviewProfile !== 2 : bodyDeclaresProfile) {
|
|
8127
|
+
throw schemaReviewFailure(
|
|
8128
|
+
"AP_CONFLICT",
|
|
8129
|
+
"publication_review_profile_mismatch",
|
|
8130
|
+
schemaReviewMessages.reviewProfileMismatch
|
|
8131
|
+
);
|
|
8132
|
+
}
|
|
8133
|
+
return {
|
|
8134
|
+
session: header === null ? { kind: "legacy", profile: 1 } : { kind: "negotiated", profile },
|
|
8135
|
+
body: envelope.body
|
|
8136
|
+
};
|
|
8137
|
+
}
|
|
8138
|
+
function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, profile, messages) {
|
|
8044
8139
|
assertCanonicalResponseSize(value, "publication_plan_too_large", messages);
|
|
8045
8140
|
const plan = asRecord4(value);
|
|
8046
|
-
if (!plan || !hasExactKeys3(plan, PLAN_KEYS) || !isCanonicalUuid(plan.requestId) || plan.environment !== "production" || plan.connectorId !== connectorId || !isCanonicalTimestamp(plan.connectorRevision) || !isCommitment(plan.connectorCommitment) || !isCommitment(plan.policyCommitment) || plan.candidateCommitment !== candidateCommitment || !isCommitment(plan.candidateCommitment) || !isCommitment(plan.baseCommitment) || !isCommitment(plan.planCommitment) || !Array.isArray(plan.tools) || typeof plan.applyAllowed !== "boolean" || !Array.isArray(plan.blockedReasons) || !plan.blockedReasons.every(
|
|
8141
|
+
if (!plan || !hasExactKeys3(plan, profile === 2 ? [...PLAN_KEYS, "reviewProfile"] : PLAN_KEYS) || profile === 2 && plan.reviewProfile !== 2 || !isCanonicalUuid(plan.requestId) || plan.environment !== "production" || plan.connectorId !== connectorId || !isCanonicalTimestamp(plan.connectorRevision) || !isCommitment(plan.connectorCommitment) || !isCommitment(plan.policyCommitment) || plan.candidateCommitment !== candidateCommitment || !isCommitment(plan.candidateCommitment) || !isCommitment(plan.baseCommitment) || !isCommitment(plan.planCommitment) || !Array.isArray(plan.tools) || typeof plan.applyAllowed !== "boolean" || !Array.isArray(plan.blockedReasons) || !plan.blockedReasons.every(
|
|
8047
8142
|
(reason) => typeof reason === "string" && BLOCKED_REASONS.has(reason)
|
|
8048
8143
|
) || !isStrictlySorted(plan.blockedReasons) || plan.applyAllowed !== (plan.blockedReasons.length === 0)) {
|
|
8049
8144
|
throw responseInvalid("publication_plan_invalid", messages);
|
|
@@ -8052,6 +8147,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8052
8147
|
let safeDiff;
|
|
8053
8148
|
try {
|
|
8054
8149
|
safeDiff = parsePublicationSafeDiffDto({
|
|
8150
|
+
...profile === 2 ? { reviewProfile: 2 } : {},
|
|
8055
8151
|
tools: plan.tools,
|
|
8056
8152
|
retainedTools: plan.retainedTools,
|
|
8057
8153
|
warnings: plan.warnings
|
|
@@ -8059,13 +8155,16 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8059
8155
|
} catch {
|
|
8060
8156
|
throw responseInvalid("publication_safe_diff_invalid", messages);
|
|
8061
8157
|
}
|
|
8158
|
+
if (safeDiff.reviewProfile === 2 !== (profile === 2)) {
|
|
8159
|
+
throw responseInvalid("publication_safe_diff_invalid", messages);
|
|
8160
|
+
}
|
|
8062
8161
|
const tools = safeDiff.tools;
|
|
8063
8162
|
const toolNames = tools.map((tool) => tool.toolName);
|
|
8064
8163
|
if (!isStrictlySorted(toolNames) || JSON.stringify(toolNames) !== JSON.stringify(expectedToolNames)) {
|
|
8065
8164
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8066
8165
|
}
|
|
8067
8166
|
const warnings = safeDiff.warnings;
|
|
8068
|
-
const expectedPlanCommitment = publicationCommitment2("plan", {
|
|
8167
|
+
const expectedPlanCommitment = publicationCommitment2(profile === 2 ? "planV2" : "plan", {
|
|
8069
8168
|
candidateCommitment,
|
|
8070
8169
|
baseCommitment: plan.baseCommitment,
|
|
8071
8170
|
connectorId,
|
|
@@ -8093,6 +8192,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8093
8192
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8094
8193
|
}
|
|
8095
8194
|
return {
|
|
8195
|
+
...profile === 2 ? { reviewProfile: 2 } : {},
|
|
8096
8196
|
requestId: plan.requestId,
|
|
8097
8197
|
environment: "production",
|
|
8098
8198
|
connectorId,
|
|
@@ -8220,8 +8320,36 @@ function typedStatus2(error) {
|
|
|
8220
8320
|
const status = error.status;
|
|
8221
8321
|
return typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 ? status : void 0;
|
|
8222
8322
|
}
|
|
8223
|
-
function
|
|
8323
|
+
function typedPublicationReason(error, code) {
|
|
8324
|
+
if (error === null || typeof error !== "object") return void 0;
|
|
8325
|
+
const status = typedStatus2(error);
|
|
8326
|
+
if (status === void 0 || status < 400 || status > 499) return void 0;
|
|
8327
|
+
const reason = error.publicationReason;
|
|
8328
|
+
return isPublicationErrorReasonFor(code, reason) ? reason : void 0;
|
|
8329
|
+
}
|
|
8330
|
+
function publicationReasonText(reason, schemaReviewMessages) {
|
|
8331
|
+
switch (reason) {
|
|
8332
|
+
case "publication_schema_review_too_large":
|
|
8333
|
+
return schemaReviewMessages.schemaReviewTooLarge;
|
|
8334
|
+
case "publication_review_profile_invalid":
|
|
8335
|
+
return schemaReviewMessages.reviewProfileInvalid;
|
|
8336
|
+
case "schema_review_receipt_mismatch":
|
|
8337
|
+
return schemaReviewMessages.receiptMismatch;
|
|
8338
|
+
case "publication_plan_stale":
|
|
8339
|
+
return schemaReviewMessages.planStale;
|
|
8340
|
+
}
|
|
8341
|
+
}
|
|
8342
|
+
function remoteError(error, phase, messages, schemaReviewMessages) {
|
|
8224
8343
|
const code = typedCode2(error) ?? "AP_NETWORK_ERROR";
|
|
8344
|
+
const publicationReason = schemaReviewMessages === void 0 ? void 0 : typedPublicationReason(error, code);
|
|
8345
|
+
if (publicationReason !== void 0 && schemaReviewMessages !== void 0) {
|
|
8346
|
+
return schemaReviewFailure(
|
|
8347
|
+
code,
|
|
8348
|
+
publicationReason,
|
|
8349
|
+
publicationReasonText(publicationReason, schemaReviewMessages),
|
|
8350
|
+
typedStatus2(error)
|
|
8351
|
+
);
|
|
8352
|
+
}
|
|
8225
8353
|
return new PublishCommandError(
|
|
8226
8354
|
code,
|
|
8227
8355
|
`${phase}_failed`,
|
|
@@ -8283,6 +8411,42 @@ function writeSafeJson(writer, value) {
|
|
|
8283
8411
|
function writePlan(writer, plan) {
|
|
8284
8412
|
writeSafeJson(writer, { phase: "plan", ...plan });
|
|
8285
8413
|
}
|
|
8414
|
+
function writeSchemaReviewSummary(writer, plan, schemaReviewMessages) {
|
|
8415
|
+
if (plan.reviewProfile !== 2) return;
|
|
8416
|
+
const reviewed = plan.tools.filter((tool) => (tool.schemaReview?.enums.length ?? 0) > 0);
|
|
8417
|
+
if (reviewed.length === 0) return;
|
|
8418
|
+
interactive(writer, schemaReviewMessages.heading);
|
|
8419
|
+
for (const tool of reviewed) {
|
|
8420
|
+
const review = tool.schemaReview;
|
|
8421
|
+
if (!review) continue;
|
|
8422
|
+
const count = (change) => review.enums.filter((entry) => entry.change === change).length;
|
|
8423
|
+
interactive(
|
|
8424
|
+
writer,
|
|
8425
|
+
schemaReviewMessages.toolSummary({
|
|
8426
|
+
toolName: terminalSafeText(tool.toolName),
|
|
8427
|
+
total: review.enums.length,
|
|
8428
|
+
added: count("added"),
|
|
8429
|
+
changed: count("changed"),
|
|
8430
|
+
removed: count("removed"),
|
|
8431
|
+
unchanged: count("unchanged"),
|
|
8432
|
+
valueReviewRequired: review.humanValueReviewRequired
|
|
8433
|
+
})
|
|
8434
|
+
);
|
|
8435
|
+
}
|
|
8436
|
+
if (reviewed.some((tool) => tool.schemaReview?.humanValueReviewRequired === true)) {
|
|
8437
|
+
interactive(writer, schemaReviewMessages.valueReviewInWebAdmin);
|
|
8438
|
+
}
|
|
8439
|
+
}
|
|
8440
|
+
function candidateNeedsReviewProfile2(candidateContract) {
|
|
8441
|
+
return selectPublicationReviewProfile({
|
|
8442
|
+
requestedProfile: CLI_PUBLICATION_REVIEW_PROFILE,
|
|
8443
|
+
candidateContract,
|
|
8444
|
+
currentTools: []
|
|
8445
|
+
}) === 2;
|
|
8446
|
+
}
|
|
8447
|
+
function applyPublicationWithProfile(client, projectId, idempotencyKey, body, session) {
|
|
8448
|
+
return session.kind === "negotiated" ? client.applyPublication(projectId, idempotencyKey, body, REVIEW_PROFILE_REQUEST) : client.applyPublication(projectId, idempotencyKey, body);
|
|
8449
|
+
}
|
|
8286
8450
|
function writeResult(writer, result) {
|
|
8287
8451
|
writeSafeJson(writer, { phase: "result", ...result });
|
|
8288
8452
|
}
|
|
@@ -8375,7 +8539,13 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
|
|
|
8375
8539
|
for (let attempt = 0; attempt < INITIAL_APPLY_MAX_ATTEMPTS; attempt += 1) {
|
|
8376
8540
|
try {
|
|
8377
8541
|
const result = parsePublicationResult(
|
|
8378
|
-
await
|
|
8542
|
+
await applyPublicationWithProfile(
|
|
8543
|
+
input.client,
|
|
8544
|
+
input.projectId,
|
|
8545
|
+
input.idempotencyKey,
|
|
8546
|
+
input.body,
|
|
8547
|
+
input.session
|
|
8548
|
+
),
|
|
8379
8549
|
input.plan,
|
|
8380
8550
|
input.messages
|
|
8381
8551
|
);
|
|
@@ -8401,7 +8571,7 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
|
|
|
8401
8571
|
return { kind: "confirmation_required", details: confirmationRequired };
|
|
8402
8572
|
}
|
|
8403
8573
|
if (!malformedConfirmationAnchor && !initialApplyResultMayBeUnknown(error)) {
|
|
8404
|
-
throw remoteError(error, "initial_apply", input.messages);
|
|
8574
|
+
throw remoteError(error, "initial_apply", input.messages, input.schemaReviewMessages);
|
|
8405
8575
|
}
|
|
8406
8576
|
if (attempt === INITIAL_APPLY_MAX_ATTEMPTS - 1) {
|
|
8407
8577
|
throw new PublishCommandError(
|
|
@@ -8526,7 +8696,7 @@ async function pollPublication(client, projectId, details, plan, writer, runtime
|
|
|
8526
8696
|
}
|
|
8527
8697
|
throw confirmationStopped("AP_CONFIRMATION_EXPIRED", "publication_poll_attempt_limit", messages);
|
|
8528
8698
|
}
|
|
8529
|
-
async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
|
|
8699
|
+
async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
|
|
8530
8700
|
const normalized = normalizePublishOptions(options, messages);
|
|
8531
8701
|
const project = loadPublicationProject(runtime.loadProject, cwd, messages);
|
|
8532
8702
|
const projectId = project.manifest.project_id;
|
|
@@ -8547,18 +8717,25 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8547
8717
|
const client = runtime.createClient(normalized.profile);
|
|
8548
8718
|
let rawPlan;
|
|
8549
8719
|
try {
|
|
8550
|
-
rawPlan = await client.planPublication(projectId, planRequest);
|
|
8720
|
+
rawPlan = await client.planPublication(projectId, planRequest, REVIEW_PROFILE_REQUEST);
|
|
8551
8721
|
} catch (error) {
|
|
8552
|
-
throw remoteError(error, "plan", messages);
|
|
8722
|
+
throw remoteError(error, "plan", messages, schemaReviewMessages);
|
|
8553
8723
|
}
|
|
8724
|
+
const negotiated = negotiateReviewProfile(rawPlan, messages, schemaReviewMessages);
|
|
8725
|
+
const session = negotiated.session;
|
|
8554
8726
|
const plan = parsePlan(
|
|
8555
|
-
|
|
8727
|
+
negotiated.body,
|
|
8556
8728
|
connectorId,
|
|
8557
8729
|
planRequest.candidateCommitment,
|
|
8558
8730
|
expectedToolNames,
|
|
8731
|
+
session.profile,
|
|
8559
8732
|
messages
|
|
8560
8733
|
);
|
|
8561
8734
|
writePlan(writer, plan);
|
|
8735
|
+
writeSchemaReviewSummary(writer, plan, schemaReviewMessages);
|
|
8736
|
+
if (session.kind === "legacy" && plan.blockedReasons.includes("opaque_change") && candidateNeedsReviewProfile2(planRequest.candidateContract)) {
|
|
8737
|
+
interactive(writer, schemaReviewMessages.adminApiUpdatePending);
|
|
8738
|
+
}
|
|
8562
8739
|
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
8563
8740
|
interactive(writer, messages.connectorMismatchRemediation);
|
|
8564
8741
|
}
|
|
@@ -8589,7 +8766,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8589
8766
|
idempotencyKey,
|
|
8590
8767
|
body: initialApplyRequest,
|
|
8591
8768
|
plan,
|
|
8592
|
-
|
|
8769
|
+
session,
|
|
8770
|
+
messages,
|
|
8771
|
+
schemaReviewMessages
|
|
8593
8772
|
});
|
|
8594
8773
|
let details;
|
|
8595
8774
|
if (initial.kind === "response") {
|
|
@@ -8618,7 +8797,13 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8618
8797
|
}
|
|
8619
8798
|
try {
|
|
8620
8799
|
const result = parsePublicationResult(
|
|
8621
|
-
await
|
|
8800
|
+
await applyPublicationWithProfile(
|
|
8801
|
+
client,
|
|
8802
|
+
projectId,
|
|
8803
|
+
idempotencyKey,
|
|
8804
|
+
applyRequest(decision.confirmation),
|
|
8805
|
+
session
|
|
8806
|
+
),
|
|
8622
8807
|
plan,
|
|
8623
8808
|
messages,
|
|
8624
8809
|
details.publicationId
|
|
@@ -8628,7 +8813,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8628
8813
|
} catch (error) {
|
|
8629
8814
|
if (error instanceof PublishCommandError && error.code === "AP_RESPONSE_INVALID") {
|
|
8630
8815
|
} else if (!approvedApplyResultMayBeUnknown(error)) {
|
|
8631
|
-
throw remoteError(error, "approved_apply", messages);
|
|
8816
|
+
throw remoteError(error, "approved_apply", messages, schemaReviewMessages);
|
|
8632
8817
|
}
|
|
8633
8818
|
}
|
|
8634
8819
|
const recovered = await pollPublication(
|
|
@@ -8651,7 +8836,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8651
8836
|
}
|
|
8652
8837
|
writeResult(writer, recovered.result);
|
|
8653
8838
|
}
|
|
8654
|
-
function registerPublish(program, writer, cwd, createClient, description2 = "Tool Contract\u3092production publication workflow\u3067\u5B89\u5168\u306B\u516C\u958B\u3057\u307E\u3059", runtime = createPublishCommandRuntime(createClient), messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
|
|
8839
|
+
function registerPublish(program, writer, cwd, createClient, description2 = "Tool Contract\u3092production publication workflow\u3067\u5B89\u5168\u306B\u516C\u958B\u3057\u307E\u3059", runtime = createPublishCommandRuntime(createClient), messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
|
|
8655
8840
|
program.command("publish").description(description2).option("--connector <connector-uuid>", messages.connectorOption).option("--dry-run", messages.dryRunOption, false).option("--apply", messages.applyOption, false).option("--yes", messages.yesOption, false).option("--profile <name>", messages.profileOption, DEFAULT_PROFILE_NAME).option("--project <project-uuid>", messages.projectOption).action(async (commandOptions) => {
|
|
8656
8841
|
await runPublishCommand(
|
|
8657
8842
|
commandOptions,
|
|
@@ -8659,7 +8844,8 @@ function registerPublish(program, writer, cwd, createClient, description2 = "Too
|
|
|
8659
8844
|
cwd(),
|
|
8660
8845
|
runtime,
|
|
8661
8846
|
messages,
|
|
8662
|
-
scopeRegistrationMessages
|
|
8847
|
+
scopeRegistrationMessages,
|
|
8848
|
+
schemaReviewMessages
|
|
8663
8849
|
);
|
|
8664
8850
|
});
|
|
8665
8851
|
}
|
|
@@ -9520,7 +9706,8 @@ function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale
|
|
|
9520
9706
|
text.publishDescription,
|
|
9521
9707
|
void 0,
|
|
9522
9708
|
messages.publish,
|
|
9523
|
-
scopeRegistrationMessages
|
|
9709
|
+
scopeRegistrationMessages,
|
|
9710
|
+
PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES2[locale]
|
|
9524
9711
|
);
|
|
9525
9712
|
return program;
|
|
9526
9713
|
}
|