@riddledc/riddle-proof 0.7.112 → 0.7.114

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.
@@ -1054,6 +1054,13 @@ function normalizeLinkStatusContentType(value) {
1054
1054
  const normalized = value?.split(";")[0]?.trim().toLowerCase();
1055
1055
  return normalized || void 0;
1056
1056
  }
1057
+ function linkStatusContentTypesMatch(actual, expected) {
1058
+ if (!actual || !expected) return false;
1059
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
1060
+ if (actual === expected) return true;
1061
+ const yamlTypes = /* @__PURE__ */ new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
1062
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
1063
+ }
1057
1064
  function linkStatusContentTypeOk(result, check) {
1058
1065
  const expected = check.allowed_content_types;
1059
1066
  if (!expected?.length) return true;
@@ -1062,8 +1069,7 @@ function linkStatusContentTypeOk(result, check) {
1062
1069
  return expected.some((contentType) => {
1063
1070
  const normalized = normalizeLinkStatusContentType(contentType);
1064
1071
  if (!normalized) return false;
1065
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
1066
- return actual === normalized;
1072
+ return linkStatusContentTypesMatch(actual, normalized);
1067
1073
  });
1068
1074
  }
1069
1075
  function httpStatusBodyContainsFailures(result, check) {
@@ -2474,6 +2480,13 @@ function normalizeLinkStatusContentType(value) {
2474
2480
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
2475
2481
  return normalized || undefined;
2476
2482
  }
2483
+ function linkStatusContentTypesMatch(actual, expected) {
2484
+ if (!actual || !expected) return false;
2485
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
2486
+ if (actual === expected) return true;
2487
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
2488
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
2489
+ }
2477
2490
  function linkStatusContentTypeOk(result, check) {
2478
2491
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
2479
2492
  const actual = normalizeLinkStatusContentType(result.content_type);
@@ -2481,8 +2494,7 @@ function linkStatusContentTypeOk(result, check) {
2481
2494
  return check.allowed_content_types.some((contentType) => {
2482
2495
  const normalized = normalizeLinkStatusContentType(contentType);
2483
2496
  if (!normalized) return false;
2484
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
2485
- return actual === normalized;
2497
+ return linkStatusContentTypesMatch(actual, normalized);
2486
2498
  });
2487
2499
  }
2488
2500
  function httpStatusBodyContainsFailures(result, check) {
@@ -4618,6 +4630,13 @@ function normalizeLinkProbeContentType(value) {
4618
4630
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
4619
4631
  return normalized || undefined;
4620
4632
  }
4633
+ function linkProbeContentTypesMatch(actual, expected) {
4634
+ if (!actual || !expected) return false;
4635
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
4636
+ if (actual === expected) return true;
4637
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
4638
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
4639
+ }
4621
4640
  function linkProbeContentTypeAllowed(result, check) {
4622
4641
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
4623
4642
  const actual = normalizeLinkProbeContentType(result.content_type);
@@ -4625,8 +4644,7 @@ function linkProbeContentTypeAllowed(result, check) {
4625
4644
  return check.allowed_content_types.some((contentType) => {
4626
4645
  const normalized = normalizeLinkProbeContentType(contentType);
4627
4646
  if (!normalized) return false;
4628
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
4629
- return actual === normalized;
4647
+ return linkProbeContentTypesMatch(actual, normalized);
4630
4648
  });
4631
4649
  }
4632
4650
  function linkProbeResponseFields(response, method) {
@@ -14,6 +14,9 @@ var RiddleApiError = class extends Error {
14
14
  this.path = pathname;
15
15
  }
16
16
  };
17
+ var PREVIEW_PUBLISH_RECOVERY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
18
+ var PREVIEW_PUBLISH_RECOVERY_ATTEMPTS = 30;
19
+ var PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS = 2e3;
17
20
  function normalizeBaseUrl(value) {
18
21
  return (value || DEFAULT_RIDDLE_API_BASE_URL).replace(/\/$/, "");
19
22
  }
@@ -48,6 +51,45 @@ async function riddleRequestJson(config, pathname, init = {}) {
48
51
  if (!response.ok) throw new RiddleApiError(pathname, response.status, text);
49
52
  return json ?? text;
50
53
  }
54
+ function previewDeployResultFromRecord(input) {
55
+ const { record, id, label, framework, expiresAt, publishRecovered, publishError } = input;
56
+ return {
57
+ ok: true,
58
+ id: String(record.id || record.preview_id || id),
59
+ label,
60
+ framework,
61
+ preview_url: String(record.preview_url || ""),
62
+ file_count: typeof record.file_count === "number" ? record.file_count : void 0,
63
+ total_bytes: typeof record.total_bytes === "number" ? record.total_bytes : void 0,
64
+ expires_at: expiresAt,
65
+ publish_recovered: publishRecovered || void 0,
66
+ publish_error: publishError,
67
+ raw: record
68
+ };
69
+ }
70
+ function canRecoverPreviewPublish(error) {
71
+ return error instanceof RiddleApiError && PREVIEW_PUBLISH_RECOVERY_STATUSES.has(error.status);
72
+ }
73
+ async function waitForPublishedPreview(config, input) {
74
+ for (let attempt = 1; attempt <= PREVIEW_PUBLISH_RECOVERY_ATTEMPTS; attempt += 1) {
75
+ const status = await riddleRequestJson(config, `/v1/preview/${input.id}`);
76
+ if (String(status.status || "") === "ready" && String(status.preview_url || "").trim()) {
77
+ return previewDeployResultFromRecord({
78
+ record: status,
79
+ id: input.id,
80
+ label: input.label,
81
+ framework: input.framework,
82
+ expiresAt: input.expiresAt,
83
+ publishRecovered: true,
84
+ publishError: input.publishError.message
85
+ });
86
+ }
87
+ if (attempt < PREVIEW_PUBLISH_RECOVERY_ATTEMPTS) {
88
+ await new Promise((resolve) => setTimeout(resolve, PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS));
89
+ }
90
+ }
91
+ throw input.publishError;
92
+ }
51
93
  async function deployRiddlePreview(config, directory, label, framework = "static") {
52
94
  if (!directory?.trim()) throw new Error("directory is required");
53
95
  if (!label?.trim()) throw new Error("label is required");
@@ -74,20 +116,22 @@ async function deployRiddlePreview(config, directory, label, framework = "static
74
116
  } finally {
75
117
  rmSync(scratch, { recursive: true, force: true });
76
118
  }
77
- const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
78
- method: "POST"
79
- });
80
- return {
81
- ok: true,
82
- id: String(published.id || id),
83
- label,
84
- framework,
85
- preview_url: String(published.preview_url || ""),
86
- file_count: typeof published.file_count === "number" ? published.file_count : void 0,
87
- total_bytes: typeof published.total_bytes === "number" ? published.total_bytes : void 0,
88
- expires_at: typeof created.expires_at === "string" ? created.expires_at : void 0,
89
- raw: published
90
- };
119
+ const expiresAt = typeof created.expires_at === "string" ? created.expires_at : void 0;
120
+ try {
121
+ const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
122
+ method: "POST"
123
+ });
124
+ return previewDeployResultFromRecord({ record: published, id, label, framework, expiresAt });
125
+ } catch (error) {
126
+ if (!canRecoverPreviewPublish(error)) throw error;
127
+ return waitForPublishedPreview(config, {
128
+ id,
129
+ label,
130
+ framework,
131
+ expiresAt,
132
+ publishError: error
133
+ });
134
+ }
91
135
  }
92
136
  async function deployRiddleStaticPreview(config, directory, label) {
93
137
  return deployRiddlePreview(config, directory, label, "static");
package/dist/cli.cjs CHANGED
@@ -6575,6 +6575,9 @@ var RiddleApiError = class extends Error {
6575
6575
  this.path = pathname;
6576
6576
  }
6577
6577
  };
6578
+ var PREVIEW_PUBLISH_RECOVERY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
6579
+ var PREVIEW_PUBLISH_RECOVERY_ATTEMPTS = 30;
6580
+ var PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS = 2e3;
6578
6581
  function normalizeBaseUrl(value) {
6579
6582
  return (value || DEFAULT_RIDDLE_API_BASE_URL).replace(/\/$/, "");
6580
6583
  }
@@ -6609,6 +6612,45 @@ async function riddleRequestJson(config, pathname, init = {}) {
6609
6612
  if (!response.ok) throw new RiddleApiError(pathname, response.status, text);
6610
6613
  return json ?? text;
6611
6614
  }
6615
+ function previewDeployResultFromRecord(input) {
6616
+ const { record, id, label, framework, expiresAt, publishRecovered, publishError } = input;
6617
+ return {
6618
+ ok: true,
6619
+ id: String(record.id || record.preview_id || id),
6620
+ label,
6621
+ framework,
6622
+ preview_url: String(record.preview_url || ""),
6623
+ file_count: typeof record.file_count === "number" ? record.file_count : void 0,
6624
+ total_bytes: typeof record.total_bytes === "number" ? record.total_bytes : void 0,
6625
+ expires_at: expiresAt,
6626
+ publish_recovered: publishRecovered || void 0,
6627
+ publish_error: publishError,
6628
+ raw: record
6629
+ };
6630
+ }
6631
+ function canRecoverPreviewPublish(error) {
6632
+ return error instanceof RiddleApiError && PREVIEW_PUBLISH_RECOVERY_STATUSES.has(error.status);
6633
+ }
6634
+ async function waitForPublishedPreview(config, input) {
6635
+ for (let attempt = 1; attempt <= PREVIEW_PUBLISH_RECOVERY_ATTEMPTS; attempt += 1) {
6636
+ const status = await riddleRequestJson(config, `/v1/preview/${input.id}`);
6637
+ if (String(status.status || "") === "ready" && String(status.preview_url || "").trim()) {
6638
+ return previewDeployResultFromRecord({
6639
+ record: status,
6640
+ id: input.id,
6641
+ label: input.label,
6642
+ framework: input.framework,
6643
+ expiresAt: input.expiresAt,
6644
+ publishRecovered: true,
6645
+ publishError: input.publishError.message
6646
+ });
6647
+ }
6648
+ if (attempt < PREVIEW_PUBLISH_RECOVERY_ATTEMPTS) {
6649
+ await new Promise((resolve) => setTimeout(resolve, PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS));
6650
+ }
6651
+ }
6652
+ throw input.publishError;
6653
+ }
6612
6654
  async function deployRiddlePreview(config, directory, label, framework = "static") {
6613
6655
  if (!directory?.trim()) throw new Error("directory is required");
6614
6656
  if (!label?.trim()) throw new Error("label is required");
@@ -6635,20 +6677,22 @@ async function deployRiddlePreview(config, directory, label, framework = "static
6635
6677
  } finally {
6636
6678
  (0, import_node_fs5.rmSync)(scratch, { recursive: true, force: true });
6637
6679
  }
6638
- const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
6639
- method: "POST"
6640
- });
6641
- return {
6642
- ok: true,
6643
- id: String(published.id || id),
6644
- label,
6645
- framework,
6646
- preview_url: String(published.preview_url || ""),
6647
- file_count: typeof published.file_count === "number" ? published.file_count : void 0,
6648
- total_bytes: typeof published.total_bytes === "number" ? published.total_bytes : void 0,
6649
- expires_at: typeof created.expires_at === "string" ? created.expires_at : void 0,
6650
- raw: published
6651
- };
6680
+ const expiresAt = typeof created.expires_at === "string" ? created.expires_at : void 0;
6681
+ try {
6682
+ const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
6683
+ method: "POST"
6684
+ });
6685
+ return previewDeployResultFromRecord({ record: published, id, label, framework, expiresAt });
6686
+ } catch (error) {
6687
+ if (!canRecoverPreviewPublish(error)) throw error;
6688
+ return waitForPublishedPreview(config, {
6689
+ id,
6690
+ label,
6691
+ framework,
6692
+ expiresAt,
6693
+ publishError: error
6694
+ });
6695
+ }
6652
6696
  }
6653
6697
  async function deployRiddleStaticPreview(config, directory, label) {
6654
6698
  return deployRiddlePreview(config, directory, label, "static");
@@ -7947,6 +7991,13 @@ function normalizeLinkStatusContentType(value) {
7947
7991
  const normalized = value?.split(";")[0]?.trim().toLowerCase();
7948
7992
  return normalized || void 0;
7949
7993
  }
7994
+ function linkStatusContentTypesMatch(actual, expected) {
7995
+ if (!actual || !expected) return false;
7996
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
7997
+ if (actual === expected) return true;
7998
+ const yamlTypes = /* @__PURE__ */ new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
7999
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
8000
+ }
7950
8001
  function linkStatusContentTypeOk(result, check) {
7951
8002
  const expected = check.allowed_content_types;
7952
8003
  if (!expected?.length) return true;
@@ -7955,8 +8006,7 @@ function linkStatusContentTypeOk(result, check) {
7955
8006
  return expected.some((contentType) => {
7956
8007
  const normalized = normalizeLinkStatusContentType(contentType);
7957
8008
  if (!normalized) return false;
7958
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
7959
- return actual === normalized;
8009
+ return linkStatusContentTypesMatch(actual, normalized);
7960
8010
  });
7961
8011
  }
7962
8012
  function httpStatusBodyContainsFailures(result, check) {
@@ -9351,6 +9401,13 @@ function normalizeLinkStatusContentType(value) {
9351
9401
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
9352
9402
  return normalized || undefined;
9353
9403
  }
9404
+ function linkStatusContentTypesMatch(actual, expected) {
9405
+ if (!actual || !expected) return false;
9406
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
9407
+ if (actual === expected) return true;
9408
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
9409
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
9410
+ }
9354
9411
  function linkStatusContentTypeOk(result, check) {
9355
9412
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
9356
9413
  const actual = normalizeLinkStatusContentType(result.content_type);
@@ -9358,8 +9415,7 @@ function linkStatusContentTypeOk(result, check) {
9358
9415
  return check.allowed_content_types.some((contentType) => {
9359
9416
  const normalized = normalizeLinkStatusContentType(contentType);
9360
9417
  if (!normalized) return false;
9361
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
9362
- return actual === normalized;
9418
+ return linkStatusContentTypesMatch(actual, normalized);
9363
9419
  });
9364
9420
  }
9365
9421
  function httpStatusBodyContainsFailures(result, check) {
@@ -11495,6 +11551,13 @@ function normalizeLinkProbeContentType(value) {
11495
11551
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
11496
11552
  return normalized || undefined;
11497
11553
  }
11554
+ function linkProbeContentTypesMatch(actual, expected) {
11555
+ if (!actual || !expected) return false;
11556
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
11557
+ if (actual === expected) return true;
11558
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
11559
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
11560
+ }
11498
11561
  function linkProbeContentTypeAllowed(result, check) {
11499
11562
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
11500
11563
  const actual = normalizeLinkProbeContentType(result.content_type);
@@ -11502,8 +11565,7 @@ function linkProbeContentTypeAllowed(result, check) {
11502
11565
  return check.allowed_content_types.some((contentType) => {
11503
11566
  const normalized = normalizeLinkProbeContentType(contentType);
11504
11567
  if (!normalized) return false;
11505
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
11506
- return actual === normalized;
11568
+ return linkProbeContentTypesMatch(actual, normalized);
11507
11569
  });
11508
11570
  }
11509
11571
  function linkProbeResponseFields(response, method) {
package/dist/cli.js CHANGED
@@ -10,11 +10,11 @@ import {
10
10
  profileStatusExitCode,
11
11
  resolveRiddleProofProfileTargetUrl,
12
12
  resolveRiddleProofProfileTimeoutSec
13
- } from "./chunk-2ZZS7RD5.js";
13
+ } from "./chunk-3CND75DM.js";
14
14
  import {
15
15
  createRiddleApiClient,
16
16
  parseRiddleViewport
17
- } from "./chunk-OI57LO6Y.js";
17
+ } from "./chunk-7GHBRZHQ.js";
18
18
  import {
19
19
  createDisabledRiddleProofAgentAdapter,
20
20
  readRiddleProofRunStatus,
package/dist/index.cjs CHANGED
@@ -9784,6 +9784,13 @@ function normalizeLinkStatusContentType(value) {
9784
9784
  const normalized = value?.split(";")[0]?.trim().toLowerCase();
9785
9785
  return normalized || void 0;
9786
9786
  }
9787
+ function linkStatusContentTypesMatch(actual, expected) {
9788
+ if (!actual || !expected) return false;
9789
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
9790
+ if (actual === expected) return true;
9791
+ const yamlTypes = /* @__PURE__ */ new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
9792
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
9793
+ }
9787
9794
  function linkStatusContentTypeOk(result, check) {
9788
9795
  const expected = check.allowed_content_types;
9789
9796
  if (!expected?.length) return true;
@@ -9792,8 +9799,7 @@ function linkStatusContentTypeOk(result, check) {
9792
9799
  return expected.some((contentType) => {
9793
9800
  const normalized = normalizeLinkStatusContentType(contentType);
9794
9801
  if (!normalized) return false;
9795
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
9796
- return actual === normalized;
9802
+ return linkStatusContentTypesMatch(actual, normalized);
9797
9803
  });
9798
9804
  }
9799
9805
  function httpStatusBodyContainsFailures(result, check) {
@@ -11204,6 +11210,13 @@ function normalizeLinkStatusContentType(value) {
11204
11210
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
11205
11211
  return normalized || undefined;
11206
11212
  }
11213
+ function linkStatusContentTypesMatch(actual, expected) {
11214
+ if (!actual || !expected) return false;
11215
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
11216
+ if (actual === expected) return true;
11217
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
11218
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
11219
+ }
11207
11220
  function linkStatusContentTypeOk(result, check) {
11208
11221
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
11209
11222
  const actual = normalizeLinkStatusContentType(result.content_type);
@@ -11211,8 +11224,7 @@ function linkStatusContentTypeOk(result, check) {
11211
11224
  return check.allowed_content_types.some((contentType) => {
11212
11225
  const normalized = normalizeLinkStatusContentType(contentType);
11213
11226
  if (!normalized) return false;
11214
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
11215
- return actual === normalized;
11227
+ return linkStatusContentTypesMatch(actual, normalized);
11216
11228
  });
11217
11229
  }
11218
11230
  function httpStatusBodyContainsFailures(result, check) {
@@ -13348,6 +13360,13 @@ function normalizeLinkProbeContentType(value) {
13348
13360
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
13349
13361
  return normalized || undefined;
13350
13362
  }
13363
+ function linkProbeContentTypesMatch(actual, expected) {
13364
+ if (!actual || !expected) return false;
13365
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
13366
+ if (actual === expected) return true;
13367
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
13368
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
13369
+ }
13351
13370
  function linkProbeContentTypeAllowed(result, check) {
13352
13371
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
13353
13372
  const actual = normalizeLinkProbeContentType(result.content_type);
@@ -13355,8 +13374,7 @@ function linkProbeContentTypeAllowed(result, check) {
13355
13374
  return check.allowed_content_types.some((contentType) => {
13356
13375
  const normalized = normalizeLinkProbeContentType(contentType);
13357
13376
  if (!normalized) return false;
13358
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
13359
- return actual === normalized;
13377
+ return linkProbeContentTypesMatch(actual, normalized);
13360
13378
  });
13361
13379
  }
13362
13380
  function linkProbeResponseFields(response, method) {
@@ -14458,6 +14476,9 @@ var RiddleApiError = class extends Error {
14458
14476
  this.path = pathname;
14459
14477
  }
14460
14478
  };
14479
+ var PREVIEW_PUBLISH_RECOVERY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
14480
+ var PREVIEW_PUBLISH_RECOVERY_ATTEMPTS = 30;
14481
+ var PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS = 2e3;
14461
14482
  function normalizeBaseUrl(value) {
14462
14483
  return (value || DEFAULT_RIDDLE_API_BASE_URL).replace(/\/$/, "");
14463
14484
  }
@@ -14492,6 +14513,45 @@ async function riddleRequestJson(config, pathname, init = {}) {
14492
14513
  if (!response.ok) throw new RiddleApiError(pathname, response.status, text);
14493
14514
  return json ?? text;
14494
14515
  }
14516
+ function previewDeployResultFromRecord(input) {
14517
+ const { record, id, label, framework, expiresAt, publishRecovered, publishError } = input;
14518
+ return {
14519
+ ok: true,
14520
+ id: String(record.id || record.preview_id || id),
14521
+ label,
14522
+ framework,
14523
+ preview_url: String(record.preview_url || ""),
14524
+ file_count: typeof record.file_count === "number" ? record.file_count : void 0,
14525
+ total_bytes: typeof record.total_bytes === "number" ? record.total_bytes : void 0,
14526
+ expires_at: expiresAt,
14527
+ publish_recovered: publishRecovered || void 0,
14528
+ publish_error: publishError,
14529
+ raw: record
14530
+ };
14531
+ }
14532
+ function canRecoverPreviewPublish(error) {
14533
+ return error instanceof RiddleApiError && PREVIEW_PUBLISH_RECOVERY_STATUSES.has(error.status);
14534
+ }
14535
+ async function waitForPublishedPreview(config, input) {
14536
+ for (let attempt = 1; attempt <= PREVIEW_PUBLISH_RECOVERY_ATTEMPTS; attempt += 1) {
14537
+ const status = await riddleRequestJson(config, `/v1/preview/${input.id}`);
14538
+ if (String(status.status || "") === "ready" && String(status.preview_url || "").trim()) {
14539
+ return previewDeployResultFromRecord({
14540
+ record: status,
14541
+ id: input.id,
14542
+ label: input.label,
14543
+ framework: input.framework,
14544
+ expiresAt: input.expiresAt,
14545
+ publishRecovered: true,
14546
+ publishError: input.publishError.message
14547
+ });
14548
+ }
14549
+ if (attempt < PREVIEW_PUBLISH_RECOVERY_ATTEMPTS) {
14550
+ await new Promise((resolve) => setTimeout(resolve, PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS));
14551
+ }
14552
+ }
14553
+ throw input.publishError;
14554
+ }
14495
14555
  async function deployRiddlePreview(config, directory, label, framework = "static") {
14496
14556
  if (!directory?.trim()) throw new Error("directory is required");
14497
14557
  if (!label?.trim()) throw new Error("label is required");
@@ -14518,20 +14578,22 @@ async function deployRiddlePreview(config, directory, label, framework = "static
14518
14578
  } finally {
14519
14579
  (0, import_node_fs5.rmSync)(scratch, { recursive: true, force: true });
14520
14580
  }
14521
- const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
14522
- method: "POST"
14523
- });
14524
- return {
14525
- ok: true,
14526
- id: String(published.id || id),
14527
- label,
14528
- framework,
14529
- preview_url: String(published.preview_url || ""),
14530
- file_count: typeof published.file_count === "number" ? published.file_count : void 0,
14531
- total_bytes: typeof published.total_bytes === "number" ? published.total_bytes : void 0,
14532
- expires_at: typeof created.expires_at === "string" ? created.expires_at : void 0,
14533
- raw: published
14534
- };
14581
+ const expiresAt = typeof created.expires_at === "string" ? created.expires_at : void 0;
14582
+ try {
14583
+ const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
14584
+ method: "POST"
14585
+ });
14586
+ return previewDeployResultFromRecord({ record: published, id, label, framework, expiresAt });
14587
+ } catch (error) {
14588
+ if (!canRecoverPreviewPublish(error)) throw error;
14589
+ return waitForPublishedPreview(config, {
14590
+ id,
14591
+ label,
14592
+ framework,
14593
+ expiresAt,
14594
+ publishError: error
14595
+ });
14596
+ }
14535
14597
  }
14536
14598
  async function deployRiddleStaticPreview(config, directory, label) {
14537
14599
  return deployRiddlePreview(config, directory, label, "static");
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ import {
59
59
  resolveRiddleProofProfileTimeoutSec,
60
60
  slugifyRiddleProofProfileName,
61
61
  summarizeRiddleProofProfileResult
62
- } from "./chunk-2ZZS7RD5.js";
62
+ } from "./chunk-3CND75DM.js";
63
63
  import {
64
64
  DEFAULT_RIDDLE_API_BASE_URL,
65
65
  DEFAULT_RIDDLE_API_KEY_FILE,
@@ -74,7 +74,7 @@ import {
74
74
  riddleRequestJson,
75
75
  runRiddleScript,
76
76
  runRiddleServerPreview
77
- } from "./chunk-OI57LO6Y.js";
77
+ } from "./chunk-7GHBRZHQ.js";
78
78
  import {
79
79
  DEFAULT_DIAGNOSTIC_ARRAY_LIMIT,
80
80
  DEFAULT_DIAGNOSTIC_HISTORY_LIMIT,
package/dist/profile.cjs CHANGED
@@ -1098,6 +1098,13 @@ function normalizeLinkStatusContentType(value) {
1098
1098
  const normalized = value?.split(";")[0]?.trim().toLowerCase();
1099
1099
  return normalized || void 0;
1100
1100
  }
1101
+ function linkStatusContentTypesMatch(actual, expected) {
1102
+ if (!actual || !expected) return false;
1103
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
1104
+ if (actual === expected) return true;
1105
+ const yamlTypes = /* @__PURE__ */ new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
1106
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
1107
+ }
1101
1108
  function linkStatusContentTypeOk(result, check) {
1102
1109
  const expected = check.allowed_content_types;
1103
1110
  if (!expected?.length) return true;
@@ -1106,8 +1113,7 @@ function linkStatusContentTypeOk(result, check) {
1106
1113
  return expected.some((contentType) => {
1107
1114
  const normalized = normalizeLinkStatusContentType(contentType);
1108
1115
  if (!normalized) return false;
1109
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
1110
- return actual === normalized;
1116
+ return linkStatusContentTypesMatch(actual, normalized);
1111
1117
  });
1112
1118
  }
1113
1119
  function httpStatusBodyContainsFailures(result, check) {
@@ -2518,6 +2524,13 @@ function normalizeLinkStatusContentType(value) {
2518
2524
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
2519
2525
  return normalized || undefined;
2520
2526
  }
2527
+ function linkStatusContentTypesMatch(actual, expected) {
2528
+ if (!actual || !expected) return false;
2529
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
2530
+ if (actual === expected) return true;
2531
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
2532
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
2533
+ }
2521
2534
  function linkStatusContentTypeOk(result, check) {
2522
2535
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
2523
2536
  const actual = normalizeLinkStatusContentType(result.content_type);
@@ -2525,8 +2538,7 @@ function linkStatusContentTypeOk(result, check) {
2525
2538
  return check.allowed_content_types.some((contentType) => {
2526
2539
  const normalized = normalizeLinkStatusContentType(contentType);
2527
2540
  if (!normalized) return false;
2528
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
2529
- return actual === normalized;
2541
+ return linkStatusContentTypesMatch(actual, normalized);
2530
2542
  });
2531
2543
  }
2532
2544
  function httpStatusBodyContainsFailures(result, check) {
@@ -4662,6 +4674,13 @@ function normalizeLinkProbeContentType(value) {
4662
4674
  const normalized = (value.split(";")[0] || "").trim().toLowerCase();
4663
4675
  return normalized || undefined;
4664
4676
  }
4677
+ function linkProbeContentTypesMatch(actual, expected) {
4678
+ if (!actual || !expected) return false;
4679
+ if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
4680
+ if (actual === expected) return true;
4681
+ const yamlTypes = new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
4682
+ return yamlTypes.has(actual) && yamlTypes.has(expected);
4683
+ }
4665
4684
  function linkProbeContentTypeAllowed(result, check) {
4666
4685
  if (!Array.isArray(check.allowed_content_types) || !check.allowed_content_types.length) return true;
4667
4686
  const actual = normalizeLinkProbeContentType(result.content_type);
@@ -4669,8 +4688,7 @@ function linkProbeContentTypeAllowed(result, check) {
4669
4688
  return check.allowed_content_types.some((contentType) => {
4670
4689
  const normalized = normalizeLinkProbeContentType(contentType);
4671
4690
  if (!normalized) return false;
4672
- if (normalized.endsWith("/*")) return actual.startsWith(normalized.slice(0, -1));
4673
- return actual === normalized;
4691
+ return linkProbeContentTypesMatch(actual, normalized);
4674
4692
  });
4675
4693
  }
4676
4694
  function linkProbeResponseFields(response, method) {
package/dist/profile.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  resolveRiddleProofProfileTimeoutSec,
21
21
  slugifyRiddleProofProfileName,
22
22
  summarizeRiddleProofProfileResult
23
- } from "./chunk-2ZZS7RD5.js";
23
+ } from "./chunk-3CND75DM.js";
24
24
  export {
25
25
  RIDDLE_PROOF_PROFILE_CHECK_TYPES,
26
26
  RIDDLE_PROOF_PROFILE_EVIDENCE_VERSION,
@@ -60,6 +60,9 @@ var RiddleApiError = class extends Error {
60
60
  this.path = pathname;
61
61
  }
62
62
  };
63
+ var PREVIEW_PUBLISH_RECOVERY_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
64
+ var PREVIEW_PUBLISH_RECOVERY_ATTEMPTS = 30;
65
+ var PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS = 2e3;
63
66
  function normalizeBaseUrl(value) {
64
67
  return (value || DEFAULT_RIDDLE_API_BASE_URL).replace(/\/$/, "");
65
68
  }
@@ -94,6 +97,45 @@ async function riddleRequestJson(config, pathname, init = {}) {
94
97
  if (!response.ok) throw new RiddleApiError(pathname, response.status, text);
95
98
  return json ?? text;
96
99
  }
100
+ function previewDeployResultFromRecord(input) {
101
+ const { record, id, label, framework, expiresAt, publishRecovered, publishError } = input;
102
+ return {
103
+ ok: true,
104
+ id: String(record.id || record.preview_id || id),
105
+ label,
106
+ framework,
107
+ preview_url: String(record.preview_url || ""),
108
+ file_count: typeof record.file_count === "number" ? record.file_count : void 0,
109
+ total_bytes: typeof record.total_bytes === "number" ? record.total_bytes : void 0,
110
+ expires_at: expiresAt,
111
+ publish_recovered: publishRecovered || void 0,
112
+ publish_error: publishError,
113
+ raw: record
114
+ };
115
+ }
116
+ function canRecoverPreviewPublish(error) {
117
+ return error instanceof RiddleApiError && PREVIEW_PUBLISH_RECOVERY_STATUSES.has(error.status);
118
+ }
119
+ async function waitForPublishedPreview(config, input) {
120
+ for (let attempt = 1; attempt <= PREVIEW_PUBLISH_RECOVERY_ATTEMPTS; attempt += 1) {
121
+ const status = await riddleRequestJson(config, `/v1/preview/${input.id}`);
122
+ if (String(status.status || "") === "ready" && String(status.preview_url || "").trim()) {
123
+ return previewDeployResultFromRecord({
124
+ record: status,
125
+ id: input.id,
126
+ label: input.label,
127
+ framework: input.framework,
128
+ expiresAt: input.expiresAt,
129
+ publishRecovered: true,
130
+ publishError: input.publishError.message
131
+ });
132
+ }
133
+ if (attempt < PREVIEW_PUBLISH_RECOVERY_ATTEMPTS) {
134
+ await new Promise((resolve) => setTimeout(resolve, PREVIEW_PUBLISH_RECOVERY_INTERVAL_MS));
135
+ }
136
+ }
137
+ throw input.publishError;
138
+ }
97
139
  async function deployRiddlePreview(config, directory, label, framework = "static") {
98
140
  if (!directory?.trim()) throw new Error("directory is required");
99
141
  if (!label?.trim()) throw new Error("label is required");
@@ -120,20 +162,22 @@ async function deployRiddlePreview(config, directory, label, framework = "static
120
162
  } finally {
121
163
  (0, import_node_fs.rmSync)(scratch, { recursive: true, force: true });
122
164
  }
123
- const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
124
- method: "POST"
125
- });
126
- return {
127
- ok: true,
128
- id: String(published.id || id),
129
- label,
130
- framework,
131
- preview_url: String(published.preview_url || ""),
132
- file_count: typeof published.file_count === "number" ? published.file_count : void 0,
133
- total_bytes: typeof published.total_bytes === "number" ? published.total_bytes : void 0,
134
- expires_at: typeof created.expires_at === "string" ? created.expires_at : void 0,
135
- raw: published
136
- };
165
+ const expiresAt = typeof created.expires_at === "string" ? created.expires_at : void 0;
166
+ try {
167
+ const published = await riddleRequestJson(config, `/v1/preview/${id}/publish`, {
168
+ method: "POST"
169
+ });
170
+ return previewDeployResultFromRecord({ record: published, id, label, framework, expiresAt });
171
+ } catch (error) {
172
+ if (!canRecoverPreviewPublish(error)) throw error;
173
+ return waitForPublishedPreview(config, {
174
+ id,
175
+ label,
176
+ framework,
177
+ expiresAt,
178
+ publishError: error
179
+ });
180
+ }
137
181
  }
138
182
  async function deployRiddleStaticPreview(config, directory, label) {
139
183
  return deployRiddlePreview(config, directory, label, "static");
@@ -42,6 +42,8 @@ interface RiddlePreviewDeployResult {
42
42
  file_count?: number;
43
43
  total_bytes?: number;
44
44
  expires_at?: string;
45
+ publish_recovered?: boolean;
46
+ publish_error?: string;
45
47
  raw?: Record<string, unknown>;
46
48
  }
47
49
  interface RiddleRunScriptInput {
@@ -42,6 +42,8 @@ interface RiddlePreviewDeployResult {
42
42
  file_count?: number;
43
43
  total_bytes?: number;
44
44
  expires_at?: string;
45
+ publish_recovered?: boolean;
46
+ publish_error?: string;
45
47
  raw?: Record<string, unknown>;
46
48
  }
47
49
  interface RiddleRunScriptInput {
@@ -12,7 +12,7 @@ import {
12
12
  riddleRequestJson,
13
13
  runRiddleScript,
14
14
  runRiddleServerPreview
15
- } from "./chunk-OI57LO6Y.js";
15
+ } from "./chunk-7GHBRZHQ.js";
16
16
  export {
17
17
  DEFAULT_RIDDLE_API_BASE_URL,
18
18
  DEFAULT_RIDDLE_API_KEY_FILE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riddledc/riddle-proof",
3
- "version": "0.7.112",
3
+ "version": "0.7.114",
4
4
  "description": "Reusable Riddle Proof contracts and helpers for evidence-backed agent changes.",
5
5
  "license": "MIT",
6
6
  "author": "RiddleDC",