@andpipes/cli 0.1.8 → 0.1.9
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 +170 -110
- package/dist/bin.js +1 -1
- package/dist/{chunk-KICI3MTW.js → chunk-YOEZJUW3.js} +95 -33
- package/dist/index.cjs +171 -111
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -125,7 +125,7 @@ var ADMIN_CLI_SCOPES = [
|
|
|
125
125
|
"admin.tool.read"
|
|
126
126
|
];
|
|
127
127
|
var ADMIN_CLI_DEFAULT_SCOPES = ADMIN_CLI_SCOPES.filter(
|
|
128
|
-
(scope) => !scope.startsWith("admin.audit_export.")
|
|
128
|
+
(scope) => !scope.startsWith("admin.audit_export.") && !scope.startsWith("admin.onboarding_template.")
|
|
129
129
|
);
|
|
130
130
|
var FILE_VERSION = 3;
|
|
131
131
|
var DEFAULT_PROFILE = "default";
|
|
@@ -6282,7 +6282,7 @@ import {
|
|
|
6282
6282
|
CLI_MESSAGES as CLI_MESSAGES8,
|
|
6283
6283
|
CLI_OPENAPI_TEMPLATE_MESSAGES as CLI_OPENAPI_TEMPLATE_MESSAGES3,
|
|
6284
6284
|
DEFAULT_LOCALE as DEFAULT_LOCALE7,
|
|
6285
|
-
formatCliOpenApiTemplateMessage as
|
|
6285
|
+
formatCliOpenApiTemplateMessage as formatMessage8,
|
|
6286
6286
|
OAUTH_SCOPE_REGISTRATION_MESSAGES
|
|
6287
6287
|
} from "@andpipes/localization";
|
|
6288
6288
|
import {
|
|
@@ -6917,6 +6917,39 @@ function authModeMismatchGuidance(mismatch, text = CLI_OPENAPI_TEMPLATE_MESSAGES
|
|
|
6917
6917
|
return lines.join("\n");
|
|
6918
6918
|
}
|
|
6919
6919
|
|
|
6920
|
+
// src/lib/scope-login-guidance.ts
|
|
6921
|
+
import {
|
|
6922
|
+
formatCliOpenApiTemplateMessage as formatMessage6
|
|
6923
|
+
} from "@andpipes/localization";
|
|
6924
|
+
var SCOPE_LOGIN_GUIDANCE = {
|
|
6925
|
+
ja: "\u5FC5\u8981\u306A\u6A29\u9650\u3067\u30ED\u30B0\u30A4\u30F3\u3057\u3001{profile} \u3092\u4ED8\u3051\u3066\u64CD\u4F5C\u3092\u518D\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
|
|
6926
|
+
en: "Sign in with the required permissions, then retry the operation with {profile}.",
|
|
6927
|
+
"zh-Hant": "\u8ACB\u4EE5\u6240\u9700\u6B0A\u9650\u767B\u5165\uFF0C\u7136\u5F8C\u52A0\u4E0A {profile} \u91CD\u8A66\u64CD\u4F5C\u3002",
|
|
6928
|
+
"zh-Hans": "\u8BF7\u4EE5\u6240\u9700\u6743\u9650\u767B\u5F55\uFF0C\u7136\u540E\u52A0\u4E0A {profile} \u91CD\u8BD5\u64CD\u4F5C\u3002",
|
|
6929
|
+
ko: "\uD544\uC694\uD55C \uAD8C\uD55C\uC73C\uB85C \uB85C\uADF8\uC778\uD55C \uD6C4 {profile} \uC635\uC158\uC744 \uBD99\uC5EC \uC791\uC5C5\uC744 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694.",
|
|
6930
|
+
fr: "Connectez-vous avec les autorisations requises, puis r\xE9essayez avec {profile}.",
|
|
6931
|
+
es: "Inicia sesi\xF3n con los permisos necesarios y vuelve a intentar la operaci\xF3n con {profile}.",
|
|
6932
|
+
pt: "Entre com as permiss\xF5es necess\xE1rias e tente novamente com {profile}.",
|
|
6933
|
+
it: "Accedi con le autorizzazioni richieste e riprova con {profile}.",
|
|
6934
|
+
ru: "\u0412\u043E\u0439\u0434\u0438\u0442\u0435 \u0441 \u043D\u0443\u0436\u043D\u044B\u043C\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D\u0438\u044F\u043C\u0438 \u0438 \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435 \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u044E \u0441 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u043E\u043C {profile}."
|
|
6935
|
+
};
|
|
6936
|
+
async function withScopeLoginGuidance(request, writer, locale, profile, scopes = []) {
|
|
6937
|
+
try {
|
|
6938
|
+
return await request;
|
|
6939
|
+
} catch (error) {
|
|
6940
|
+
if (error instanceof AdminApiClientError && error.status === 403 && error.code === "AP_INVALID_SCOPE") {
|
|
6941
|
+
const profileOption = `--profile ${profile}`;
|
|
6942
|
+
const scopeOption = scopes.length === 0 ? "" : ` --scope ${scopes.join(",")}`;
|
|
6943
|
+
interactive(
|
|
6944
|
+
writer,
|
|
6945
|
+
`${formatMessage6(SCOPE_LOGIN_GUIDANCE[locale], { profile: profileOption })}
|
|
6946
|
+
andpipe login ${profileOption}${scopeOption}`
|
|
6947
|
+
);
|
|
6948
|
+
}
|
|
6949
|
+
throw error;
|
|
6950
|
+
}
|
|
6951
|
+
}
|
|
6952
|
+
|
|
6920
6953
|
// src/lib/terminal-safe.ts
|
|
6921
6954
|
import { reviewDisplayText } from "@andpipes/tool-contract";
|
|
6922
6955
|
function terminalSafeText(value) {
|
|
@@ -6942,7 +6975,7 @@ import {
|
|
|
6942
6975
|
CLI_MESSAGES as CLI_MESSAGES7,
|
|
6943
6976
|
CLI_OPENAPI_TEMPLATE_MESSAGES as CLI_OPENAPI_TEMPLATE_MESSAGES2,
|
|
6944
6977
|
DEFAULT_LOCALE as DEFAULT_LOCALE6,
|
|
6945
|
-
formatCliOpenApiTemplateMessage as
|
|
6978
|
+
formatCliOpenApiTemplateMessage as formatMessage7
|
|
6946
6979
|
} from "@andpipes/localization";
|
|
6947
6980
|
import {
|
|
6948
6981
|
EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE as EXTERNAL_SAAS_TEMPLATE_COMMITMENT_RE2,
|
|
@@ -6960,13 +6993,16 @@ import {
|
|
|
6960
6993
|
var BINDINGS_MAX_BYTES = 64 * 1024;
|
|
6961
6994
|
var EXPORT_MAX_BYTES = 1280 * 1024;
|
|
6962
6995
|
var TEMPLATE_ID_RE2 = /^[a-z][a-z0-9._-]{0,63}$/u;
|
|
6996
|
+
var TEMPLATE_PROFILE = "onboarding-template";
|
|
6997
|
+
var TEMPLATE_READ_SCOPES = ["admin.onboarding_template.read"];
|
|
6998
|
+
var TEMPLATE_WRITE_SCOPES = [...TEMPLATE_READ_SCOPES, "admin.onboarding_template.write"];
|
|
6963
6999
|
function createTemplateCommandRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
|
|
6964
7000
|
return { createClient, idempotencyKey: randomUUID4 };
|
|
6965
7001
|
}
|
|
6966
7002
|
function jsonObject(text, label, messages) {
|
|
6967
7003
|
const parsed = parseToolContract4(text, { format: "json" });
|
|
6968
7004
|
if (!parsed.ok || !parsed.contract || typeof parsed.contract !== "object" || Array.isArray(parsed.contract)) {
|
|
6969
|
-
throw new UsageError(
|
|
7005
|
+
throw new UsageError(formatMessage7(messages.jsonObjectInvalid, { label }));
|
|
6970
7006
|
}
|
|
6971
7007
|
return parsed.contract;
|
|
6972
7008
|
}
|
|
@@ -7123,7 +7159,13 @@ async function runTemplatePlanOrApply(options, writer, cwd, runtime = createTemp
|
|
|
7123
7159
|
const loaded = loadOnboardingTemplateArtifact(cwd, options.file, options.bindings, messages);
|
|
7124
7160
|
const client = runtime.createClient(options.profile ?? DEFAULT_PROFILE_NAME);
|
|
7125
7161
|
if (!proof) {
|
|
7126
|
-
const plan = await
|
|
7162
|
+
const plan = await withScopeLoginGuidance(
|
|
7163
|
+
client.planOnboardingTemplate(projectId, loaded.manifest, loaded.bindings),
|
|
7164
|
+
writer,
|
|
7165
|
+
locale,
|
|
7166
|
+
TEMPLATE_PROFILE,
|
|
7167
|
+
TEMPLATE_READ_SCOPES
|
|
7168
|
+
);
|
|
7127
7169
|
assertPlanMatchesLocal(plan, projectId, loaded, messages);
|
|
7128
7170
|
json(writer, {
|
|
7129
7171
|
mode: "dry-run",
|
|
@@ -7141,15 +7183,21 @@ async function runTemplatePlanOrApply(options, writer, cwd, runtime = createTemp
|
|
|
7141
7183
|
if (loaded.exportProjectId !== void 0 && loaded.exportProjectId !== projectId) {
|
|
7142
7184
|
throw new UsageError(messages.exportProjectMismatch);
|
|
7143
7185
|
}
|
|
7144
|
-
const result = await
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7186
|
+
const result = await withScopeLoginGuidance(
|
|
7187
|
+
client.applyOnboardingTemplate(projectId, options.idempotencyKey, {
|
|
7188
|
+
scopeRiskReviewVersion: proof.scopeRiskReviewVersion,
|
|
7189
|
+
scopeRiskReview: proof.scopeRiskReview,
|
|
7190
|
+
manifest: loaded.manifest,
|
|
7191
|
+
bindings: loaded.bindings,
|
|
7192
|
+
expectedCurrentApplicationCommitment: proof.expectedCurrent,
|
|
7193
|
+
planCommitment: proof.planCommitment,
|
|
7194
|
+
confirmed: true
|
|
7195
|
+
}),
|
|
7196
|
+
writer,
|
|
7197
|
+
locale,
|
|
7198
|
+
TEMPLATE_PROFILE,
|
|
7199
|
+
TEMPLATE_WRITE_SCOPES
|
|
7200
|
+
);
|
|
7153
7201
|
assertApplyMatchesLocal(result, projectId, loaded, proof.planCommitment, messages);
|
|
7154
7202
|
if (JSON.stringify(result.scopeRiskReview) !== JSON.stringify(proof.scopeRiskReview)) {
|
|
7155
7203
|
throw new UsageError(messages.scopeMismatch);
|
|
@@ -7164,7 +7212,13 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
7164
7212
|
const targetRevision = positiveRevision(options.targetRevision, messages);
|
|
7165
7213
|
const client = runtime.createClient(options.profile ?? DEFAULT_PROFILE_NAME);
|
|
7166
7214
|
if (!proof) {
|
|
7167
|
-
const plan = await
|
|
7215
|
+
const plan = await withScopeLoginGuidance(
|
|
7216
|
+
client.planOnboardingTemplateRollback(projectId, templateId, targetRevision),
|
|
7217
|
+
writer,
|
|
7218
|
+
locale,
|
|
7219
|
+
TEMPLATE_PROFILE,
|
|
7220
|
+
TEMPLATE_READ_SCOPES
|
|
7221
|
+
);
|
|
7168
7222
|
const parsed2 = parseOnboardingTemplateSafePlanDto2(plan);
|
|
7169
7223
|
if (parsed2.projectId !== projectId || parsed2.templateId !== templateId || parsed2.operation !== "rollback" || parsed2.rollbackFromRevision !== targetRevision || parsed2.currentApplicationCommitment === null) {
|
|
7170
7224
|
throw new UsageError(messages.rollbackPlanMismatch);
|
|
@@ -7186,18 +7240,19 @@ async function runTemplateRollback(options, writer, runtime = createTemplateComm
|
|
|
7186
7240
|
if (!options.idempotencyKey) {
|
|
7187
7241
|
throw new UsageError(messages.idemRequired);
|
|
7188
7242
|
}
|
|
7189
|
-
const result = await
|
|
7190
|
-
projectId,
|
|
7191
|
-
templateId,
|
|
7192
|
-
options.idempotencyKey,
|
|
7193
|
-
{
|
|
7243
|
+
const result = await withScopeLoginGuidance(
|
|
7244
|
+
client.rollbackOnboardingTemplate(projectId, templateId, options.idempotencyKey, {
|
|
7194
7245
|
targetRevision,
|
|
7195
7246
|
scopeRiskReviewVersion: proof.scopeRiskReviewVersion,
|
|
7196
7247
|
scopeRiskReview: proof.scopeRiskReview,
|
|
7197
7248
|
expectedCurrentApplicationCommitment: proof.expectedCurrent,
|
|
7198
7249
|
planCommitment: proof.planCommitment,
|
|
7199
7250
|
confirmed: true
|
|
7200
|
-
}
|
|
7251
|
+
}),
|
|
7252
|
+
writer,
|
|
7253
|
+
locale,
|
|
7254
|
+
TEMPLATE_PROFILE,
|
|
7255
|
+
TEMPLATE_WRITE_SCOPES
|
|
7201
7256
|
);
|
|
7202
7257
|
const parsed = parseOnboardingTemplateApplyDto2(result);
|
|
7203
7258
|
if (parsed.projectId !== projectId || parsed.templateId !== templateId || parsed.operation !== "rollback" || parsed.rollbackFromRevision !== targetRevision || parsed.planCommitment !== proof.planCommitment || parsed.applicationCommitment === proof.expectedCurrent || JSON.stringify(parsed.scopeRiskReview) !== JSON.stringify(proof.scopeRiskReview)) {
|
|
@@ -7236,7 +7291,13 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
|
|
|
7236
7291
|
const templateId = canonicalTemplateId(options.template, messages);
|
|
7237
7292
|
const anchor = captureLocalRootPath(cwd());
|
|
7238
7293
|
const result = parseOnboardingTemplateExportDto2(
|
|
7239
|
-
await
|
|
7294
|
+
await withScopeLoginGuidance(
|
|
7295
|
+
runtime.createClient(options.profile).exportOnboardingTemplate(projectId, templateId),
|
|
7296
|
+
writer,
|
|
7297
|
+
locale,
|
|
7298
|
+
TEMPLATE_PROFILE,
|
|
7299
|
+
TEMPLATE_READ_SCOPES
|
|
7300
|
+
)
|
|
7240
7301
|
);
|
|
7241
7302
|
if (result.projectId !== projectId || result.manifest.templateId !== templateId) {
|
|
7242
7303
|
throw new UsageError(messages.exportMismatch);
|
|
@@ -7356,14 +7417,14 @@ async function materializeOpenApiInit(options, anchor, runtime, messages, copy)
|
|
|
7356
7417
|
}
|
|
7357
7418
|
} catch (error) {
|
|
7358
7419
|
if (error instanceof OpenApiImportError2) {
|
|
7359
|
-
throw new UsageError(
|
|
7420
|
+
throw new UsageError(formatMessage8(copy.generateFailure, { detail: error.message }));
|
|
7360
7421
|
}
|
|
7361
7422
|
throw error;
|
|
7362
7423
|
}
|
|
7363
7424
|
const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
|
|
7364
7425
|
if (blocked.length > 0) {
|
|
7365
7426
|
throw new UsageError(
|
|
7366
|
-
|
|
7427
|
+
formatMessage8(copy.initGateFailed, {
|
|
7367
7428
|
tools: blocked.map((operation) => operation.toolName).join(", ")
|
|
7368
7429
|
})
|
|
7369
7430
|
);
|
|
@@ -8065,7 +8126,7 @@ function registerInit(program, writer, cwd, createClient, description = "Project
|
|
|
8065
8126
|
(value, previous) => [...previous, value],
|
|
8066
8127
|
[]
|
|
8067
8128
|
).option("--create-connector", copy.initCreateConnectorOption, false).option("--profile <name>", messages.profileOption, DEFAULT_PROFILE_NAME).option("--yes", messages.yesOption, false).action(async (options) => {
|
|
8068
|
-
|
|
8129
|
+
const result = runInitCommand(
|
|
8069
8130
|
options,
|
|
8070
8131
|
writer,
|
|
8071
8132
|
cwd(),
|
|
@@ -8074,6 +8135,7 @@ function registerInit(program, writer, cwd, createClient, description = "Project
|
|
|
8074
8135
|
scopeRegistrationMessages,
|
|
8075
8136
|
locale
|
|
8076
8137
|
);
|
|
8138
|
+
await (options.template === void 0 ? result : withScopeLoginGuidance(result, writer, locale, DEFAULT_PROFILE_NAME));
|
|
8077
8139
|
});
|
|
8078
8140
|
}
|
|
8079
8141
|
|
|
@@ -8342,7 +8404,7 @@ import {
|
|
|
8342
8404
|
CLI_MESSAGES as CLI_MESSAGES12,
|
|
8343
8405
|
CLI_OAUTH_DOCTOR_MESSAGES as CLI_OAUTH_DOCTOR_MESSAGES3,
|
|
8344
8406
|
DEFAULT_LOCALE as DEFAULT_LOCALE11,
|
|
8345
|
-
formatCliOpenApiTemplateMessage as
|
|
8407
|
+
formatCliOpenApiTemplateMessage as formatMessage9,
|
|
8346
8408
|
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES3
|
|
8347
8409
|
} from "@andpipes/localization";
|
|
8348
8410
|
import {
|
|
@@ -9691,7 +9753,7 @@ function upstreamOAuthWizardUrl(profile, projectId, connectorId, locale = DEFAUL
|
|
|
9691
9753
|
const record = getProfile(profile);
|
|
9692
9754
|
if (!record)
|
|
9693
9755
|
throw new UsageError(
|
|
9694
|
-
|
|
9756
|
+
formatMessage9(CLI_OAUTH_DOCTOR_MESSAGES3[locale].oauth.profileMissing, { profile })
|
|
9695
9757
|
);
|
|
9696
9758
|
const url = new URL(`/projects/${projectId}/oauth`, new URL(record.verificationUriBase).origin);
|
|
9697
9759
|
url.searchParams.set("connector", connectorId);
|
|
@@ -9878,7 +9940,7 @@ function registerOauth(program, writer, locale = DEFAULT_LOCALE11, dependencies
|
|
|
9878
9940
|
}).getUpstreamOAuthConnectionState(projectId, opts.connector);
|
|
9879
9941
|
json(writer, state);
|
|
9880
9942
|
const url = upstreamOAuthWizardUrl(opts.profile, projectId, opts.connector, locale);
|
|
9881
|
-
info(writer,
|
|
9943
|
+
info(writer, formatMessage9(copy.continueInAdmin, { url }));
|
|
9882
9944
|
if (opts.browser) {
|
|
9883
9945
|
try {
|
|
9884
9946
|
(dependencies.openBrowser ?? openBrowser)(url);
|
|
@@ -9905,7 +9967,7 @@ import {
|
|
|
9905
9967
|
CLI_MESSAGES as CLI_MESSAGES13,
|
|
9906
9968
|
CLI_OPENAPI_TEMPLATE_MESSAGES as CLI_OPENAPI_TEMPLATE_MESSAGES4,
|
|
9907
9969
|
DEFAULT_LOCALE as DEFAULT_LOCALE12,
|
|
9908
|
-
formatCliOpenApiTemplateMessage as
|
|
9970
|
+
formatCliOpenApiTemplateMessage as formatMessage10
|
|
9909
9971
|
} from "@andpipes/localization";
|
|
9910
9972
|
import {
|
|
9911
9973
|
importOpenApi as importOpenApi2,
|
|
@@ -9928,13 +9990,13 @@ function normalizedOptions(options, text) {
|
|
|
9928
9990
|
const apply = options.apply === true;
|
|
9929
9991
|
const yes = options.yes === true;
|
|
9930
9992
|
if (yes && !apply) {
|
|
9931
|
-
throw new UsageError(
|
|
9993
|
+
throw new UsageError(formatMessage10(text.requiresApply, { flags: "--yes" }));
|
|
9932
9994
|
}
|
|
9933
9995
|
if (options.idempotencyKey !== void 0 && !apply) {
|
|
9934
|
-
throw new UsageError(
|
|
9996
|
+
throw new UsageError(formatMessage10(text.requiresApply, { flags: "--idempotency-key" }));
|
|
9935
9997
|
}
|
|
9936
9998
|
if (!apply && options.planCommitment !== void 0) {
|
|
9937
|
-
throw new UsageError(
|
|
9999
|
+
throw new UsageError(formatMessage10(text.requiresApply, { flags: "--plan-commitment" }));
|
|
9938
10000
|
}
|
|
9939
10001
|
return {
|
|
9940
10002
|
file: options.file,
|
|
@@ -10002,7 +10064,7 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
10002
10064
|
);
|
|
10003
10065
|
} catch (error) {
|
|
10004
10066
|
if (error instanceof OpenApiImportError3) {
|
|
10005
|
-
throw new UsageError(
|
|
10067
|
+
throw new UsageError(formatMessage10(text.generateFailure, { detail: error.message }));
|
|
10006
10068
|
}
|
|
10007
10069
|
throw error;
|
|
10008
10070
|
}
|