@contentful/experience-design-system-cli 2.37.1-dev-build-91b5f8aa.0 → 2.37.1-dev-build-a961485e.0
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/app.js
CHANGED
|
@@ -1836,6 +1836,9 @@ import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
|
1836
1836
|
// packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/repositories/migration.js
|
|
1837
1837
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
1838
1838
|
|
|
1839
|
+
// packages/experience-design-system-backend-pipeline/dist/src/persistence/src/credentials/helpers/host-utils.js
|
|
1840
|
+
var DEFAULT_CONFIGURED_HOST = "api.contentful.com";
|
|
1841
|
+
|
|
1839
1842
|
// packages/experience-design-system-backend-pipeline/dist/src/persistence/src/index.js
|
|
1840
1843
|
init_cache_keys();
|
|
1841
1844
|
|
|
@@ -2173,9 +2176,9 @@ var mergeConfigs = (a, b) => {
|
|
|
2173
2176
|
config.headers = mergeHeaders(a.headers, b.headers);
|
|
2174
2177
|
return config;
|
|
2175
2178
|
};
|
|
2176
|
-
var mergeHeaders = (...
|
|
2179
|
+
var mergeHeaders = (...headers) => {
|
|
2177
2180
|
const mergedHeaders = new Headers();
|
|
2178
|
-
for (const header of
|
|
2181
|
+
for (const header of headers) {
|
|
2179
2182
|
if (!header || typeof header !== "object") {
|
|
2180
2183
|
continue;
|
|
2181
2184
|
}
|
|
@@ -2394,9 +2397,587 @@ var createClient = (config = {}) => {
|
|
|
2394
2397
|
// packages/experience-design-system-client/dist/src/generated/client.gen.js
|
|
2395
2398
|
var client = createClient(createConfig());
|
|
2396
2399
|
|
|
2400
|
+
// packages/experience-design-system-client/dist/src/generated/sdk.gen.js
|
|
2401
|
+
var designSystemImportSourcelessPreview = (options) => {
|
|
2402
|
+
return (options.client ?? client).post({
|
|
2403
|
+
url: "/spaces/{spaceId}/environments/{environmentId}/design_systems/imports/preview",
|
|
2404
|
+
...options,
|
|
2405
|
+
headers: {
|
|
2406
|
+
"Content-Type": "application/json",
|
|
2407
|
+
...options.headers
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
};
|
|
2411
|
+
var designSystemImportApply = (options) => {
|
|
2412
|
+
return (options.client ?? client).post({
|
|
2413
|
+
url: "/spaces/{spaceId}/environments/{environmentId}/design_systems/imports/apply",
|
|
2414
|
+
...options,
|
|
2415
|
+
headers: {
|
|
2416
|
+
"Content-Type": "application/json",
|
|
2417
|
+
...options.headers
|
|
2418
|
+
}
|
|
2419
|
+
});
|
|
2420
|
+
};
|
|
2421
|
+
var designSystemImportGetOperation = (options) => {
|
|
2422
|
+
return (options.client ?? client).get({
|
|
2423
|
+
url: "/spaces/{spaceId}/environments/{environmentId}/design_systems/imports/apply/{operationId}",
|
|
2424
|
+
...options
|
|
2425
|
+
});
|
|
2426
|
+
};
|
|
2427
|
+
|
|
2428
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/constants/api.js
|
|
2429
|
+
var PREVIEW_ERROR_PREFIX = "preview failed:";
|
|
2430
|
+
var APPLY_ERROR_PREFIX = "apply failed:";
|
|
2431
|
+
var USER_AGENT = "experience-design-system-backend-pipeline";
|
|
2432
|
+
|
|
2433
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/http-utils.js
|
|
2434
|
+
var MAX_RETRY_AFTER_MS = 6e4;
|
|
2435
|
+
function isTransientStatus(status) {
|
|
2436
|
+
return status >= 500 && status <= 599;
|
|
2437
|
+
}
|
|
2438
|
+
function retryAfterMs(response) {
|
|
2439
|
+
const value = response.headers?.get("retry-after")?.trim();
|
|
2440
|
+
if (!value)
|
|
2441
|
+
return void 0;
|
|
2442
|
+
const seconds = Number(value);
|
|
2443
|
+
const delayMs = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(value) - Date.now();
|
|
2444
|
+
if (!Number.isFinite(delayMs) || delayMs < 0 || delayMs > MAX_RETRY_AFTER_MS)
|
|
2445
|
+
return void 0;
|
|
2446
|
+
return Math.round(delayMs);
|
|
2447
|
+
}
|
|
2448
|
+
function isApsDenialBody(body) {
|
|
2449
|
+
if (!body)
|
|
2450
|
+
return false;
|
|
2451
|
+
try {
|
|
2452
|
+
const parsed = JSON.parse(body);
|
|
2453
|
+
const id = parsed?.sys?.id;
|
|
2454
|
+
return id === "NotFound" || id === "AccessDenied";
|
|
2455
|
+
} catch {
|
|
2456
|
+
return false;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
function stringifyError(error) {
|
|
2460
|
+
return typeof error === "string" ? error : JSON.stringify(error ?? {});
|
|
2461
|
+
}
|
|
2462
|
+
function errorMessage(error) {
|
|
2463
|
+
return error instanceof Error && error.message ? error.message : String(error);
|
|
2464
|
+
}
|
|
2465
|
+
function defaultSleep(delayMs) {
|
|
2466
|
+
return new Promise((resolve2) => setTimeout(resolve2, delayMs));
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/sanitize-preview.js
|
|
2470
|
+
var PROPERTY_BREAKING_REASONS = /* @__PURE__ */ new Set([
|
|
2471
|
+
"removed",
|
|
2472
|
+
"added_required_no_default",
|
|
2473
|
+
"type_changed",
|
|
2474
|
+
"validation_narrowed"
|
|
2475
|
+
]);
|
|
2476
|
+
var SLOT_BREAKING_REASONS = /* @__PURE__ */ new Set(["slot_removed", "slot_allowed_components_narrowed"]);
|
|
2477
|
+
function sanitizeBreakingChanges(raw) {
|
|
2478
|
+
if (!Array.isArray(raw))
|
|
2479
|
+
return [];
|
|
2480
|
+
const out = [];
|
|
2481
|
+
for (const bc of raw) {
|
|
2482
|
+
if (typeof bc !== "object" || bc === null)
|
|
2483
|
+
continue;
|
|
2484
|
+
const reason = bc.reason;
|
|
2485
|
+
if (typeof reason !== "string")
|
|
2486
|
+
continue;
|
|
2487
|
+
if ("propertyId" in bc && typeof bc.propertyId === "string") {
|
|
2488
|
+
if (PROPERTY_BREAKING_REASONS.has(reason))
|
|
2489
|
+
out.push(bc);
|
|
2490
|
+
continue;
|
|
2491
|
+
}
|
|
2492
|
+
if ("slotId" in bc && typeof bc.slotId === "string") {
|
|
2493
|
+
if (SLOT_BREAKING_REASONS.has(reason))
|
|
2494
|
+
out.push(bc);
|
|
2495
|
+
continue;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
return out;
|
|
2499
|
+
}
|
|
2500
|
+
function sanitizePreviewResponse(res) {
|
|
2501
|
+
for (const item of res.components?.changed ?? []) {
|
|
2502
|
+
const cc = item.changeClassification;
|
|
2503
|
+
if (cc && Array.isArray(cc.breakingChanges)) {
|
|
2504
|
+
cc.breakingChanges = sanitizeBreakingChanges(cc.breakingChanges);
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
return res;
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/host-utils.js
|
|
2511
|
+
var DEFAULT_API_HOST = "https://api.contentful.com";
|
|
2512
|
+
function trimTrailingSlashes(value) {
|
|
2513
|
+
return value.replace(/\/+$/, "");
|
|
2514
|
+
}
|
|
2515
|
+
function normalizeHostInput(host) {
|
|
2516
|
+
const value = host?.trim();
|
|
2517
|
+
if (!value)
|
|
2518
|
+
return void 0;
|
|
2519
|
+
return trimTrailingSlashes(value);
|
|
2520
|
+
}
|
|
2521
|
+
function toConfiguredHost2(host) {
|
|
2522
|
+
const normalized = normalizeHostInput(host);
|
|
2523
|
+
if (!normalized)
|
|
2524
|
+
return void 0;
|
|
2525
|
+
return normalized.replace(/^https:\/\//i, "");
|
|
2526
|
+
}
|
|
2527
|
+
function toApiHost2(host) {
|
|
2528
|
+
const normalized = normalizeHostInput(host);
|
|
2529
|
+
if (!normalized)
|
|
2530
|
+
return DEFAULT_API_HOST;
|
|
2531
|
+
if (/^[a-z][a-z\d+\-.]*:\/\//i.test(normalized))
|
|
2532
|
+
return normalized;
|
|
2533
|
+
return `https://${normalized}`;
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/types/api-error.js
|
|
2537
|
+
var ERROR_BODY_LOG_CAP = 16384;
|
|
2538
|
+
var ApiError = class extends Error {
|
|
2539
|
+
status;
|
|
2540
|
+
body;
|
|
2541
|
+
guidance;
|
|
2542
|
+
constructor(message, status, body, guidance) {
|
|
2543
|
+
super(message);
|
|
2544
|
+
this.status = status;
|
|
2545
|
+
this.body = body;
|
|
2546
|
+
this.guidance = guidance;
|
|
2547
|
+
if (body) {
|
|
2548
|
+
const trimmed = body.length > ERROR_BODY_LOG_CAP ? body.slice(0, ERROR_BODY_LOG_CAP) + "\u2026" : body;
|
|
2549
|
+
this.message = `${message}
|
|
2550
|
+
${trimmed}`;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
|
|
2555
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/api-client/api-client.js
|
|
2556
|
+
var ApiClient = class {
|
|
2557
|
+
host;
|
|
2558
|
+
token;
|
|
2559
|
+
spaceId;
|
|
2560
|
+
environmentId;
|
|
2561
|
+
retry;
|
|
2562
|
+
lastRequestId;
|
|
2563
|
+
constructor(opts) {
|
|
2564
|
+
this.host = toApiHost2(opts.host);
|
|
2565
|
+
this.token = opts.cmaToken;
|
|
2566
|
+
this.spaceId = opts.spaceId;
|
|
2567
|
+
this.environmentId = opts.environmentId;
|
|
2568
|
+
const initialDelayMs = Math.max(0, opts.retry?.initialDelayMs ?? 250);
|
|
2569
|
+
this.retry = {
|
|
2570
|
+
maxAttempts: Math.max(1, Math.floor(opts.retry?.maxAttempts ?? 3)),
|
|
2571
|
+
initialDelayMs,
|
|
2572
|
+
maxDelayMs: Math.max(initialDelayMs, opts.retry?.maxDelayMs ?? 2e3),
|
|
2573
|
+
sleep: opts.retry?.sleep ?? defaultSleep
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
getLastRequestId() {
|
|
2577
|
+
return this.lastRequestId;
|
|
2578
|
+
}
|
|
2579
|
+
noteRequestId(response) {
|
|
2580
|
+
const id = response.headers.get("x-contentful-request-id");
|
|
2581
|
+
if (id)
|
|
2582
|
+
this.lastRequestId = id;
|
|
2583
|
+
}
|
|
2584
|
+
headers() {
|
|
2585
|
+
return {
|
|
2586
|
+
Authorization: `Bearer ${this.token}`,
|
|
2587
|
+
"Content-Type": "application/json",
|
|
2588
|
+
"X-Contentful-User-Agent": USER_AGENT
|
|
2589
|
+
};
|
|
2590
|
+
}
|
|
2591
|
+
async requestWithRetry(phase, errorPrefix, makeCall) {
|
|
2592
|
+
for (let attempt = 1; attempt <= this.retry.maxAttempts; attempt++) {
|
|
2593
|
+
let result;
|
|
2594
|
+
try {
|
|
2595
|
+
result = await makeCall();
|
|
2596
|
+
} catch (error) {
|
|
2597
|
+
if (attempt === this.retry.maxAttempts) {
|
|
2598
|
+
const body = `The request failed after ${attempt} attempts because of a network error: ${errorMessage(error)}. Check your connection and try again.`;
|
|
2599
|
+
throw new ApiError(`${errorPrefix} 0`, 0, body);
|
|
2600
|
+
}
|
|
2601
|
+
await this.retry.sleep(Math.min(this.retry.initialDelayMs * 2 ** (attempt - 1), this.retry.maxDelayMs));
|
|
2602
|
+
continue;
|
|
2603
|
+
}
|
|
2604
|
+
if (!isTransientStatus(result.response.status)) {
|
|
2605
|
+
this.noteRequestId(result.response);
|
|
2606
|
+
return result;
|
|
2607
|
+
}
|
|
2608
|
+
if (attempt === this.retry.maxAttempts) {
|
|
2609
|
+
const body = stringifyError(result.error);
|
|
2610
|
+
const guidance = `The ${phase} request failed after ${attempt} attempts because the service remained unavailable. Wait a moment and try again.`;
|
|
2611
|
+
throw new ApiError(`${errorPrefix} ${result.response.status}`, result.response.status, body, guidance);
|
|
2612
|
+
}
|
|
2613
|
+
const backoffMs = Math.min(this.retry.initialDelayMs * 2 ** (attempt - 1), this.retry.maxDelayMs);
|
|
2614
|
+
await this.retry.sleep(retryAfterMs(result.response) ?? backoffMs);
|
|
2615
|
+
}
|
|
2616
|
+
throw new Error("Retry attempts exhausted");
|
|
2617
|
+
}
|
|
2618
|
+
async validateToken() {
|
|
2619
|
+
const res = await fetch(`${this.host}/users/me`, { headers: this.headers() });
|
|
2620
|
+
this.noteRequestId(res);
|
|
2621
|
+
if (res.status === 401) {
|
|
2622
|
+
throw new ApiError("CMA token is invalid or revoked", res.status, await res.text());
|
|
2623
|
+
}
|
|
2624
|
+
if (!res.ok) {
|
|
2625
|
+
throw new ApiError(`unexpected error validating token: ${res.status}`, res.status, await res.text());
|
|
2626
|
+
}
|
|
2627
|
+
await this.checkPreflight();
|
|
2628
|
+
}
|
|
2629
|
+
async checkPreflight() {
|
|
2630
|
+
const url = `${this.host}/spaces/${this.spaceId}/environments/${this.environmentId}/design_systems/preflight`;
|
|
2631
|
+
let res;
|
|
2632
|
+
try {
|
|
2633
|
+
res = await fetch(url, { headers: this.headers() });
|
|
2634
|
+
} catch {
|
|
2635
|
+
return;
|
|
2636
|
+
}
|
|
2637
|
+
this.noteRequestId(res);
|
|
2638
|
+
if (res.ok)
|
|
2639
|
+
return;
|
|
2640
|
+
if (res.status >= 500)
|
|
2641
|
+
return;
|
|
2642
|
+
const body = await res.text();
|
|
2643
|
+
if (res.status === 404 && !isApsDenialBody(body))
|
|
2644
|
+
return;
|
|
2645
|
+
throw new ApiError(`preflight failed: ${res.status}`, res.status, body);
|
|
2646
|
+
}
|
|
2647
|
+
async previewImport(cdf) {
|
|
2648
|
+
const result = await this.requestWithRetry("preview", PREVIEW_ERROR_PREFIX, () => designSystemImportSourcelessPreview({
|
|
2649
|
+
baseUrl: this.host,
|
|
2650
|
+
headers: this.headers(),
|
|
2651
|
+
path: { spaceId: this.spaceId, environmentId: this.environmentId },
|
|
2652
|
+
body: cdf,
|
|
2653
|
+
parseAs: "json"
|
|
2654
|
+
}));
|
|
2655
|
+
if (!result.response.ok) {
|
|
2656
|
+
throw new ApiError(`${PREVIEW_ERROR_PREFIX} ${result.response.status}`, result.response.status, stringifyError(result.error));
|
|
2657
|
+
}
|
|
2658
|
+
return sanitizePreviewResponse(result.data);
|
|
2659
|
+
}
|
|
2660
|
+
async applyImport(cdf, opts) {
|
|
2661
|
+
let result;
|
|
2662
|
+
try {
|
|
2663
|
+
result = await designSystemImportApply({
|
|
2664
|
+
baseUrl: this.host,
|
|
2665
|
+
headers: this.headers(),
|
|
2666
|
+
path: { spaceId: this.spaceId, environmentId: this.environmentId },
|
|
2667
|
+
body: { ...cdf, acknowledgeBreakingChanges: opts.acknowledgeBreakingChanges },
|
|
2668
|
+
parseAs: "json"
|
|
2669
|
+
});
|
|
2670
|
+
} catch (error) {
|
|
2671
|
+
const body = `The apply request was not retried because its outcome is unknown and retrying could start a duplicate operation. Cause: ${errorMessage(error)}`;
|
|
2672
|
+
throw new ApiError(`${APPLY_ERROR_PREFIX} 0`, 0, body);
|
|
2673
|
+
}
|
|
2674
|
+
if (!result.response.ok) {
|
|
2675
|
+
const body = stringifyError(result.error);
|
|
2676
|
+
const guidance = isTransientStatus(result.response.status) ? "The apply request was not retried because the server may already have started an operation and retrying could create a duplicate." : void 0;
|
|
2677
|
+
throw new ApiError(`${APPLY_ERROR_PREFIX} ${result.response.status}`, result.response.status, body, guidance);
|
|
2678
|
+
}
|
|
2679
|
+
this.noteRequestId(result.response);
|
|
2680
|
+
return result.data;
|
|
2681
|
+
}
|
|
2682
|
+
async pollOperation(operationId, opts = {}) {
|
|
2683
|
+
const intervalMs = opts.intervalMs ?? 2e3;
|
|
2684
|
+
const maxIntervalMs = opts.maxIntervalMs ?? Math.round(intervalMs * 2.5);
|
|
2685
|
+
const maxAttempts = opts.maxAttempts ?? 150;
|
|
2686
|
+
const terminalStatuses = /* @__PURE__ */ new Set(["succeeded", "partial", "failed"]);
|
|
2687
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
2688
|
+
const result = await this.requestWithRetry("poll", "poll failed:", () => designSystemImportGetOperation({
|
|
2689
|
+
baseUrl: this.host,
|
|
2690
|
+
headers: this.headers(),
|
|
2691
|
+
path: { spaceId: this.spaceId, environmentId: this.environmentId, operationId },
|
|
2692
|
+
parseAs: "json"
|
|
2693
|
+
}));
|
|
2694
|
+
if (!result.response.ok) {
|
|
2695
|
+
throw new ApiError(`poll failed: ${result.response.status}`, result.response.status, stringifyError(result.error));
|
|
2696
|
+
}
|
|
2697
|
+
const op = result.data;
|
|
2698
|
+
opts.onProgress?.(op);
|
|
2699
|
+
if (terminalStatuses.has(op.sys.status))
|
|
2700
|
+
return op;
|
|
2701
|
+
if (attempt < maxAttempts - 1) {
|
|
2702
|
+
const progress = maxAttempts > 1 ? attempt / (maxAttempts - 1) : 0;
|
|
2703
|
+
const baseDelay = intervalMs + (maxIntervalMs - intervalMs) * progress;
|
|
2704
|
+
const jitter = Math.random() * baseDelay * 0.15;
|
|
2705
|
+
await new Promise((resolve2) => setTimeout(resolve2, baseDelay + jitter));
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
throw new Error(`Operation ${operationId} timed out after ${maxAttempts} attempts`);
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2397
2712
|
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/controller/validation/assert-no-unresolved-slot-references.js
|
|
2398
2713
|
init_shared();
|
|
2399
2714
|
|
|
2715
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-binding-diagnostics.js
|
|
2716
|
+
function parseBindingDiagnostics(body) {
|
|
2717
|
+
if (!/binding configurations are invalid|Pointer path does not exist/i.test(body))
|
|
2718
|
+
return null;
|
|
2719
|
+
const locationMatches = [...body.matchAll(/(?:^|\.\s)([A-Za-z0-9_$-]+(?:\s*›\s*[A-Za-z0-9_$-]+){2,})/g)];
|
|
2720
|
+
const location = locationMatches.at(-1)?.[1];
|
|
2721
|
+
const pointerMessage = body.match(/Pointer path does not exist for '\[object Object\]':\s*(.+?)(?=\.\s*Default\s*›|$)/i)?.[1];
|
|
2722
|
+
const graphQlMessage = body.match(/return GraphQL validation error:\s*(.+?)(?=\.\s*Default\s*›|$)/i)?.[1];
|
|
2723
|
+
const heading = body.match(/^(.*?)(?=\.?\s*Pointer path does not exist|\.?\s*Default\s*›)/i)?.[1]?.trim();
|
|
2724
|
+
const diagnostics = [];
|
|
2725
|
+
if (pointerMessage)
|
|
2726
|
+
diagnostics.push({ message: pointerMessage.trim(), ...location ? { path: location } : {} });
|
|
2727
|
+
if (graphQlMessage)
|
|
2728
|
+
diagnostics.push({ message: graphQlMessage.trim(), ...location ? { path: location } : {} });
|
|
2729
|
+
return {
|
|
2730
|
+
code: "BindingValidationFailed",
|
|
2731
|
+
message: heading || "One or more binding configurations are invalid.",
|
|
2732
|
+
...diagnostics.length > 0 ? { diagnostics } : {}
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/helpers.js
|
|
2737
|
+
function asRecord(value) {
|
|
2738
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
2739
|
+
}
|
|
2740
|
+
function displayValue(value) {
|
|
2741
|
+
if (typeof value === "string")
|
|
2742
|
+
return value;
|
|
2743
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
2744
|
+
return String(value);
|
|
2745
|
+
if (value === null || value === void 0)
|
|
2746
|
+
return null;
|
|
2747
|
+
try {
|
|
2748
|
+
return JSON.stringify(value);
|
|
2749
|
+
} catch {
|
|
2750
|
+
return null;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
function isPathSegment(value) {
|
|
2754
|
+
return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
2755
|
+
}
|
|
2756
|
+
function formatPath(value) {
|
|
2757
|
+
if (isPathSegment(value))
|
|
2758
|
+
return String(value) ? { path: String(value) } : { path: null };
|
|
2759
|
+
if (Array.isArray(value)) {
|
|
2760
|
+
const parts = value.filter(isPathSegment);
|
|
2761
|
+
return parts.length > 0 ? { path: parts.join(" \u203A ") } : { path: null };
|
|
2762
|
+
}
|
|
2763
|
+
return {};
|
|
2764
|
+
}
|
|
2765
|
+
function componentFromPath(path5) {
|
|
2766
|
+
if (!path5)
|
|
2767
|
+
return void 0;
|
|
2768
|
+
const manifestMatch = path5.match(/manifest:components\/([^/›]+)/);
|
|
2769
|
+
if (manifestMatch?.[1])
|
|
2770
|
+
return manifestMatch[1];
|
|
2771
|
+
const parts = path5.split(/[›/]/).map((part) => part.trim()).filter(Boolean);
|
|
2772
|
+
const componentsIndex = parts.findIndex((part) => part === "components");
|
|
2773
|
+
return componentsIndex === -1 ? void 0 : parts[componentsIndex + 1];
|
|
2774
|
+
}
|
|
2775
|
+
function diagnosticMessage(error) {
|
|
2776
|
+
const candidates = [
|
|
2777
|
+
["message", error.message],
|
|
2778
|
+
["details", error.details],
|
|
2779
|
+
["error", error.error],
|
|
2780
|
+
["name", error.name]
|
|
2781
|
+
];
|
|
2782
|
+
for (const [messageSource, value] of candidates) {
|
|
2783
|
+
const message = displayValue(value);
|
|
2784
|
+
if (message !== null)
|
|
2785
|
+
return { message, messageSource };
|
|
2786
|
+
}
|
|
2787
|
+
return { message: "Validation failed" };
|
|
2788
|
+
}
|
|
2789
|
+
function parseObjectLiteralTail(body) {
|
|
2790
|
+
const braceStart = body.lastIndexOf("{");
|
|
2791
|
+
if (braceStart === -1)
|
|
2792
|
+
return null;
|
|
2793
|
+
const tail = body.slice(braceStart);
|
|
2794
|
+
const codeMatch = tail.match(/code:\s*['"]([^'"]+)['"]/);
|
|
2795
|
+
const cycleMatch = tail.match(/cycle:\s*\[\s*([^\]]*)\s*\]/);
|
|
2796
|
+
if (!codeMatch && !cycleMatch)
|
|
2797
|
+
return null;
|
|
2798
|
+
const code = codeMatch ? codeMatch[1] : null;
|
|
2799
|
+
let cycle = null;
|
|
2800
|
+
if (cycleMatch) {
|
|
2801
|
+
cycle = cycleMatch[1].split(",").map((s) => s.trim().replace(/^['"]|['"]$/g, "")).filter((s) => s.length > 0);
|
|
2802
|
+
if (cycle.length === 0)
|
|
2803
|
+
cycle = null;
|
|
2804
|
+
}
|
|
2805
|
+
return { code, cycle };
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-json-body.js
|
|
2809
|
+
function parseValidationDiagnostics(details) {
|
|
2810
|
+
if (!Array.isArray(details.errors))
|
|
2811
|
+
return [];
|
|
2812
|
+
const diagnostics = [];
|
|
2813
|
+
for (const rawError of details.errors) {
|
|
2814
|
+
const error = asRecord(rawError);
|
|
2815
|
+
if (!error)
|
|
2816
|
+
continue;
|
|
2817
|
+
const location = formatPath(error.path);
|
|
2818
|
+
const component = displayValue(error.component ?? error.componentName ?? error.componentId) ?? componentFromPath(location.path);
|
|
2819
|
+
diagnostics.push({ ...diagnosticMessage(error), ...location, ...component ? { component } : {} });
|
|
2820
|
+
}
|
|
2821
|
+
return diagnostics;
|
|
2822
|
+
}
|
|
2823
|
+
function parseJsonBody(body) {
|
|
2824
|
+
let parsed;
|
|
2825
|
+
try {
|
|
2826
|
+
parsed = JSON.parse(body);
|
|
2827
|
+
} catch {
|
|
2828
|
+
return null;
|
|
2829
|
+
}
|
|
2830
|
+
const p = asRecord(parsed);
|
|
2831
|
+
if (!p)
|
|
2832
|
+
return null;
|
|
2833
|
+
const details = asRecord(p.details) ?? {};
|
|
2834
|
+
const pick = (k) => p[k] !== void 0 ? p[k] : details[k];
|
|
2835
|
+
const codeRaw = pick("code") ?? asRecord(p.sys)?.id;
|
|
2836
|
+
const messageRaw = pick("message");
|
|
2837
|
+
const cycleRaw = pick("cycle");
|
|
2838
|
+
const out = {};
|
|
2839
|
+
if (typeof codeRaw === "string")
|
|
2840
|
+
out.code = codeRaw;
|
|
2841
|
+
if (typeof messageRaw === "string")
|
|
2842
|
+
out.message = messageRaw;
|
|
2843
|
+
if (Array.isArray(cycleRaw)) {
|
|
2844
|
+
const strs = cycleRaw.filter((x) => typeof x === "string");
|
|
2845
|
+
if (strs.length > 0)
|
|
2846
|
+
out.cycle = strs;
|
|
2847
|
+
}
|
|
2848
|
+
const diagnostics = parseValidationDiagnostics(details);
|
|
2849
|
+
if (diagnostics.length > 0)
|
|
2850
|
+
out.diagnostics = diagnostics;
|
|
2851
|
+
return out;
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/strip-lambda-log-prefix.js
|
|
2855
|
+
var LAMBDA_LOG_PREFIX_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\s+[0-9a-f-]+\s+ERROR\s+(?:\[dd\.[^\]]*\]\s*)?/;
|
|
2856
|
+
var DD_TAG_RE = /\[dd\.(?:trace_id|span_id)=[^\]]*\]\s*/g;
|
|
2857
|
+
function stripLambdaLogPrefix(body) {
|
|
2858
|
+
return body.replace(LAMBDA_LOG_PREFIX_RE, "").replace(DD_TAG_RE, "").trim();
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-edsi-error.js
|
|
2862
|
+
var API_ERROR_PREFIX_RE = /^(?:apply|preview|poll) failed: \d+$/;
|
|
2863
|
+
function parseEdsiError(rawInput) {
|
|
2864
|
+
if (!rawInput)
|
|
2865
|
+
return { code: null, message: "", cycle: null, raw: true };
|
|
2866
|
+
const { body, prefix } = splitPhasePrefix(rawInput);
|
|
2867
|
+
const cleaned = stripLambdaLogPrefix(body);
|
|
2868
|
+
const json = parseJsonBody(cleaned) ?? parseJsonBody(body);
|
|
2869
|
+
const bindingFromJson = typeof json?.message === "string" ? parseBindingDiagnostics(json.message) : null;
|
|
2870
|
+
if (bindingFromJson) {
|
|
2871
|
+
return {
|
|
2872
|
+
code: bindingFromJson.code ?? json?.code ?? null,
|
|
2873
|
+
message: bindingFromJson.message ?? cleaned,
|
|
2874
|
+
cycle: null,
|
|
2875
|
+
raw: false,
|
|
2876
|
+
...bindingFromJson.diagnostics ? { diagnostics: bindingFromJson.diagnostics } : {}
|
|
2877
|
+
};
|
|
2878
|
+
}
|
|
2879
|
+
if (json && (json.code || json.message || json.cycle)) {
|
|
2880
|
+
return {
|
|
2881
|
+
code: json.code ?? null,
|
|
2882
|
+
message: json.message ?? (cleaned || prefix),
|
|
2883
|
+
cycle: json.cycle ?? null,
|
|
2884
|
+
raw: false,
|
|
2885
|
+
...json.diagnostics ? { diagnostics: json.diagnostics } : {}
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
const binding = parseBindingDiagnostics(cleaned);
|
|
2889
|
+
if (binding) {
|
|
2890
|
+
return {
|
|
2891
|
+
code: binding.code ?? null,
|
|
2892
|
+
message: binding.message ?? cleaned,
|
|
2893
|
+
cycle: null,
|
|
2894
|
+
raw: false,
|
|
2895
|
+
...binding.diagnostics ? { diagnostics: binding.diagnostics } : {}
|
|
2896
|
+
};
|
|
2897
|
+
}
|
|
2898
|
+
const literal2 = parseObjectLiteralTail(cleaned);
|
|
2899
|
+
if (literal2 && (literal2.code || literal2.cycle)) {
|
|
2900
|
+
const braceStart = cleaned.lastIndexOf("{");
|
|
2901
|
+
const head = braceStart === -1 ? cleaned : cleaned.slice(0, braceStart).trim();
|
|
2902
|
+
return { code: literal2.code ?? null, message: head || cleaned, cycle: literal2.cycle ?? null, raw: false };
|
|
2903
|
+
}
|
|
2904
|
+
return { code: null, message: cleaned || prefix || rawInput, cycle: null, raw: true };
|
|
2905
|
+
}
|
|
2906
|
+
function splitPhasePrefix(input) {
|
|
2907
|
+
const nlIndex = input.indexOf("\n");
|
|
2908
|
+
if (nlIndex === -1)
|
|
2909
|
+
return { body: input, prefix: "" };
|
|
2910
|
+
const firstLine = input.slice(0, nlIndex);
|
|
2911
|
+
if (!API_ERROR_PREFIX_RE.test(firstLine))
|
|
2912
|
+
return { body: input, prefix: "" };
|
|
2913
|
+
return { body: input.slice(nlIndex + 1), prefix: firstLine };
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-parsed-edsi-error.js
|
|
2917
|
+
function formatParsedEdsiError(parsed, opts = {}) {
|
|
2918
|
+
const lines = [];
|
|
2919
|
+
if (parsed.code)
|
|
2920
|
+
lines.push(`[${parsed.code}]`);
|
|
2921
|
+
if (parsed.message)
|
|
2922
|
+
lines.push(parsed.message);
|
|
2923
|
+
for (const diagnostic of parsed.diagnostics ?? []) {
|
|
2924
|
+
const context = [
|
|
2925
|
+
diagnostic.component ? `Component: ${diagnostic.component}` : null,
|
|
2926
|
+
diagnostic.path ? `Path: ${diagnostic.path}` : null
|
|
2927
|
+
].filter(Boolean);
|
|
2928
|
+
lines.push(`- ${diagnostic.message}${context.length > 0 ? ` (${context.join("; ")})` : ""}`);
|
|
2929
|
+
if (diagnostic.path === null) {
|
|
2930
|
+
lines.push(" Location: not provided by the server. Review the submitted CDF file; no component or field was identified.");
|
|
2931
|
+
}
|
|
2932
|
+
if (opts.verbose && diagnostic.messageSource) {
|
|
2933
|
+
lines.push(` Message field: ${diagnostic.messageSource}`);
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
if (parsed.code === "BindingValidationFailed") {
|
|
2937
|
+
const location = parsed.diagnostics?.find((d) => d.path)?.path;
|
|
2938
|
+
lines.push(location ? `Next action: review the binding at ${location} and correct its pointer or GraphQL selection.` : "Next action: review the binding pointer and GraphQL selection.");
|
|
2939
|
+
}
|
|
2940
|
+
if (parsed.code === "AccessDenied") {
|
|
2941
|
+
lines.push("Next action: this operation requires DesignToken and Component permissions in this environment. Ask a Contentful admin to grant both on your role.");
|
|
2942
|
+
}
|
|
2943
|
+
if (parsed.code === "NotFound") {
|
|
2944
|
+
lines.push("Next action: verify the resource id is correct. If it should exist, your role may lack read permission on DesignToken or Component.");
|
|
2945
|
+
}
|
|
2946
|
+
if (parsed.cycle && parsed.cycle.length > 0) {
|
|
2947
|
+
lines.push(`Cycle: ${parsed.cycle.join(" \u2192 ")} \u2192 ${parsed.cycle[0]}`);
|
|
2948
|
+
lines.push("Break the cycle by removing at least one $allowedComponents entry.");
|
|
2949
|
+
}
|
|
2950
|
+
if (opts.verbose && opts.raw) {
|
|
2951
|
+
lines.push("");
|
|
2952
|
+
lines.push("--- raw ---");
|
|
2953
|
+
lines.push(opts.raw);
|
|
2954
|
+
}
|
|
2955
|
+
return lines.filter(Boolean).join("\n");
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-edsi-error.js
|
|
2959
|
+
function formatEdsiError(raw, opts = {}) {
|
|
2960
|
+
const input = typeof raw === "string" ? raw : displayValue(raw);
|
|
2961
|
+
if (!input)
|
|
2962
|
+
return "";
|
|
2963
|
+
return formatParsedEdsiError(parseEdsiError(input), { ...opts, raw: opts.raw ?? input });
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-api-error.js
|
|
2967
|
+
function formatApiError(error, verbose = false) {
|
|
2968
|
+
const formatted = formatEdsiError(error.body || error.message, { verbose, raw: error.body }) || error.message;
|
|
2969
|
+
const phase = error.message.split("\n", 1)[0];
|
|
2970
|
+
const withPhase = /^(?:apply|preview|poll) failed: \d+$/.test(phase) && formatted !== phase ? `${phase}
|
|
2971
|
+
${formatted}` : formatted;
|
|
2972
|
+
return error.guidance ? `${withPhase}
|
|
2973
|
+
${error.guidance}` : withPhase;
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/controller/errors/format-api-error.js
|
|
2977
|
+
function formatApiError2(request) {
|
|
2978
|
+
return formatApiError(request.error, request.verbose ?? false);
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2400
2981
|
// packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/tokens/read-tokens-from-path.js
|
|
2401
2982
|
init_shared();
|
|
2402
2983
|
|
|
@@ -2535,7 +3116,6 @@ import { useInput as useInput6 } from "ink";
|
|
|
2535
3116
|
|
|
2536
3117
|
// packages/experience-design-system-cli/src/tui/import/steps/04-credentials/logic.ts
|
|
2537
3118
|
var FIELDS = ["spaceId", "environmentId", "cmaToken", "host"];
|
|
2538
|
-
var DEFAULT_HOST = "api.contentful.com";
|
|
2539
3119
|
function keyAction2(input, key) {
|
|
2540
3120
|
if (key.escape) return "back";
|
|
2541
3121
|
if (key.tab) return "next-field";
|
|
@@ -2545,21 +3125,12 @@ function keyAction2(input, key) {
|
|
|
2545
3125
|
function nextField(field) {
|
|
2546
3126
|
return FIELDS[(FIELDS.indexOf(field) + 1) % FIELDS.length];
|
|
2547
3127
|
}
|
|
2548
|
-
function toConfiguredHost3(host) {
|
|
2549
|
-
const value = (host ?? "").trim().replace(/\/+$/, "");
|
|
2550
|
-
return value === "" ? DEFAULT_HOST : value.replace(/^https:\/\//i, "");
|
|
2551
|
-
}
|
|
2552
|
-
function toApiHost3(host) {
|
|
2553
|
-
const value = host.trim().replace(/\/+$/, "");
|
|
2554
|
-
if (value === "") return `https://${DEFAULT_HOST}`;
|
|
2555
|
-
return /^[a-z][a-z\d+\-.]*:\/\//i.test(value) ? value : `https://${value}`;
|
|
2556
|
-
}
|
|
2557
3128
|
function normalize(values) {
|
|
2558
3129
|
return {
|
|
2559
3130
|
spaceId: values.spaceId.trim(),
|
|
2560
3131
|
environmentId: values.environmentId.trim(),
|
|
2561
3132
|
cmaToken: values.cmaToken.trim(),
|
|
2562
|
-
host:
|
|
3133
|
+
host: toConfiguredHost2(values.host) ?? DEFAULT_CONFIGURED_HOST
|
|
2563
3134
|
};
|
|
2564
3135
|
}
|
|
2565
3136
|
function missingField(values) {
|
|
@@ -2587,59 +3158,30 @@ function useCredentialsControls(handlers) {
|
|
|
2587
3158
|
}
|
|
2588
3159
|
|
|
2589
3160
|
// packages/experience-design-system-cli/src/tui/import/steps/04-credentials/validate.ts
|
|
2590
|
-
var USER_AGENT2 = "app contentful.experience-design-system-cli";
|
|
2591
|
-
function headers(token) {
|
|
2592
|
-
return { Authorization: `Bearer ${token}`, "X-Contentful-User-Agent": USER_AGENT2 };
|
|
2593
|
-
}
|
|
2594
|
-
function isApsDenial(body) {
|
|
2595
|
-
try {
|
|
2596
|
-
const id = JSON.parse(body).sys?.id;
|
|
2597
|
-
return id === "NotFound" || id === "AccessDenied";
|
|
2598
|
-
} catch {
|
|
2599
|
-
return false;
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
function messageFrom(body) {
|
|
2603
|
-
try {
|
|
2604
|
-
const message = JSON.parse(body).message;
|
|
2605
|
-
return typeof message === "string" && message !== "" ? message : void 0;
|
|
2606
|
-
} catch {
|
|
2607
|
-
return void 0;
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
3161
|
async function validateCredentials(values) {
|
|
2611
|
-
const
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
}
|
|
2618
|
-
if (me.status === 401) return { ok: false, error: "CMA token is invalid or revoked." };
|
|
2619
|
-
if (!me.ok) return { ok: false, error: `Unexpected error validating the token (${me.status}).` };
|
|
2620
|
-
let preflight;
|
|
3162
|
+
const host = toApiHost2(values.host);
|
|
3163
|
+
const client2 = new ApiClient({
|
|
3164
|
+
host,
|
|
3165
|
+
spaceId: values.spaceId,
|
|
3166
|
+
environmentId: values.environmentId,
|
|
3167
|
+
cmaToken: values.cmaToken
|
|
3168
|
+
});
|
|
2621
3169
|
try {
|
|
2622
|
-
|
|
2623
|
-
`${base}/spaces/${values.spaceId}/environments/${values.environmentId}/design_systems/preflight`,
|
|
2624
|
-
{ headers: headers(values.cmaToken) }
|
|
2625
|
-
);
|
|
2626
|
-
} catch {
|
|
3170
|
+
await client2.validateToken();
|
|
2627
3171
|
return { ok: true };
|
|
3172
|
+
} catch (error) {
|
|
3173
|
+
return { ok: false, error: toUserError(error, host) };
|
|
2628
3174
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
if (
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
if (preflight.status === 404) {
|
|
2637
|
-
return {
|
|
2638
|
-
ok: false,
|
|
2639
|
-
error: `Not found. Check the space ID, environment and API host.${detail ? ` (${detail})` : ""}`
|
|
2640
|
-
};
|
|
3175
|
+
}
|
|
3176
|
+
function toUserError(error, host) {
|
|
3177
|
+
if (error instanceof ApiError) {
|
|
3178
|
+
if (error.status === 404 && error.message.startsWith("preflight failed:")) {
|
|
3179
|
+
return "Not found. Check the space ID, environment and API host.";
|
|
3180
|
+
}
|
|
3181
|
+
return formatApiError2({ error });
|
|
2641
3182
|
}
|
|
2642
|
-
|
|
3183
|
+
if (error instanceof Error) return `Could not reach ${host}: ${error.message}`;
|
|
3184
|
+
return String(error);
|
|
2643
3185
|
}
|
|
2644
3186
|
|
|
2645
3187
|
// packages/experience-design-system-cli/src/tui/import/steps/04-credentials/screen.tsx
|
|
@@ -2716,7 +3258,7 @@ function CredentialsScreen({
|
|
|
2716
3258
|
value: values[field],
|
|
2717
3259
|
focus: active === field && !validating,
|
|
2718
3260
|
mask: field === "cmaToken" ? "\u2022" : void 0,
|
|
2719
|
-
placeholder: field === "host" ?
|
|
3261
|
+
placeholder: field === "host" ? DEFAULT_CONFIGURED_HOST : void 0,
|
|
2720
3262
|
onChange: change(field),
|
|
2721
3263
|
onSubmit: () => void submit(field)
|
|
2722
3264
|
}
|