react-semaphor 0.1.449 → 0.1.454

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.
Files changed (147) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +119 -112
  3. package/dist/appearance/index.cjs +1 -1
  4. package/dist/appearance/index.js +1 -1
  5. package/dist/brand-studio/index.cjs +4 -4
  6. package/dist/brand-studio/index.js +15 -13
  7. package/dist/briefings/index.cjs +1 -1
  8. package/dist/briefings/index.js +39 -2131
  9. package/dist/chunks/{analyze-result-contract-T-0Ntzys.js → analyze-result-contract-BbRJ-C06.js} +1 -1
  10. package/dist/chunks/{analyze-result-contract-BHb7sUUW.cjs → analyze-result-contract-LPDNldic.cjs} +1 -1
  11. package/dist/chunks/canonical-result-keys-BA0HCP4e.cjs +1 -0
  12. package/dist/chunks/canonical-result-keys-D6avdjpA.js +467 -0
  13. package/dist/chunks/color-CJvdlFM_.js +2162 -0
  14. package/dist/chunks/color-CyB5o13F.cjs +4 -0
  15. package/dist/chunks/{common-types-CQ6SHfLk.cjs → common-types-C57kJ59w.cjs} +1 -1
  16. package/dist/chunks/{common-types-B7Jk3Rtj.js → common-types-H51FLKB7.js} +1 -1
  17. package/dist/chunks/contracts-CoCOpd_i.js +11 -0
  18. package/dist/chunks/contracts-CtB2VONT.cjs +1 -0
  19. package/dist/chunks/dashboard-briefing-launcher-Dwj1i7lr.cjs +26 -0
  20. package/dist/chunks/{dashboard-briefing-launcher-DCHiEkLE.js → dashboard-briefing-launcher-SYroFdae.js} +86 -84
  21. package/dist/chunks/{dashboard-controls-DwRFCcHV.js → dashboard-controls-1LpeU2sz.js} +15 -13
  22. package/dist/chunks/{dashboard-controls-CaFioayc.cjs → dashboard-controls-CpFoh7-A.cjs} +1 -1
  23. package/dist/chunks/dashboard-date-comparison-definition-Ces4alFm.cjs +1 -0
  24. package/dist/chunks/{dashboard-date-comparison-definition-Ba-clViK.js → dashboard-date-comparison-definition-DC3ekV2S.js} +1 -1
  25. package/dist/chunks/{dashboard-json-WoILbfTe.js → dashboard-json-D-T-sQxU.js} +25 -23
  26. package/dist/chunks/dashboard-json-DwSQopc_.cjs +1 -0
  27. package/dist/chunks/edit-dashboard-visual-BEmoQAET.cjs +172 -0
  28. package/dist/chunks/{edit-dashboard-visual-ciFhxqaI.js → edit-dashboard-visual-DqxUq4Bs.js} +6925 -6947
  29. package/dist/chunks/editor-action-buttons-18r2xwei.cjs +16 -0
  30. package/dist/chunks/{editor-action-buttons-BPo_45pM.js → editor-action-buttons-B2l3WIRC.js} +41 -39
  31. package/dist/chunks/format-types-CFHQoIuk.js +1350 -0
  32. package/dist/chunks/format-types-PSZZ7hG8.cjs +1 -0
  33. package/dist/chunks/index-Bn5wlkHt.cjs +4 -0
  34. package/dist/chunks/index-ByFbacH7.cjs +1 -0
  35. package/dist/chunks/index-CACdoqu3.js +318 -0
  36. package/dist/chunks/index-CLB_NGZ8.cjs +1392 -0
  37. package/dist/chunks/index-Ca784dpx.js +3714 -0
  38. package/dist/chunks/{index-CPuawpXJ.js → index-DAoS4BNU.js} +48514 -48484
  39. package/dist/chunks/index-DSKR3nKn.js +421 -0
  40. package/dist/chunks/index-F25jnH0p.cjs +1 -0
  41. package/dist/chunks/matrix-result-contract-CofATICL.js +437 -0
  42. package/dist/chunks/matrix-result-contract-zamd9euI.cjs +1 -0
  43. package/dist/chunks/pivot-header-presentation-DhyQXxKq.cjs +4 -0
  44. package/dist/chunks/pivot-header-presentation-ckYOQ4aZ.js +557 -0
  45. package/dist/chunks/{pivot-result-identity-CDLRT-YG.cjs → pivot-result-identity-Bb4EixVN.cjs} +1 -1
  46. package/dist/chunks/{pivot-result-identity-CwJWpKI7.js → pivot-result-identity-DU1v-5Xk.js} +1 -1
  47. package/dist/chunks/pivot-result-lifecycle-DmcF1ris.cjs +1 -0
  48. package/dist/chunks/pivot-result-lifecycle-sjzIOpvp.js +1641 -0
  49. package/dist/chunks/raw-temporal-contract-BtjH_G-d.cjs +1 -0
  50. package/dist/chunks/raw-temporal-contract-CxncLze5.js +64 -0
  51. package/dist/chunks/report-preferences-dialog-BgSvlDXa.cjs +1 -0
  52. package/dist/chunks/report-preferences-dialog-DDc2WUa0.js +723 -0
  53. package/dist/chunks/{report-runtime-context-C8LZFsqV.cjs → report-runtime-context-DqxS4wbi.cjs} +1 -1
  54. package/dist/chunks/{report-runtime-context-bCy3CVzK.js → report-runtime-context-SM6YO61_.js} +5 -5
  55. package/dist/chunks/saved-temporal-bucket-format-CFfWXRl9.cjs +1 -0
  56. package/dist/chunks/saved-temporal-bucket-format-SGAV0ivR.js +922 -0
  57. package/dist/chunks/{switch-BXet-Sno.js → switch-BeZW-HnS.js} +4350 -5249
  58. package/dist/chunks/switch-D-CCcfhc.cjs +138 -0
  59. package/dist/chunks/temporal-bucket-5UYEotyQ.js +810 -0
  60. package/dist/chunks/temporal-bucket-DHY1y9lq.cjs +1 -0
  61. package/dist/chunks/temporal-bucket-authoring-K1kE6R_z.js +222 -0
  62. package/dist/chunks/temporal-bucket-authoring-o3Emn05L.cjs +1 -0
  63. package/dist/chunks/{temporal-bucket-contract-ChDBWX8I.cjs → temporal-bucket-contract-D2-93DGr.cjs} +1 -1
  64. package/dist/chunks/{temporal-bucket-contract-_F6vNhhH.js → temporal-bucket-contract-D5d-xEl3.js} +1 -1
  65. package/dist/chunks/{token-types-BdQ8kHBm.cjs → token-types-D7CaaI80.cjs} +1 -1
  66. package/dist/chunks/{token-types-BHR58aTy.js → token-types-GbxRUozo.js} +1 -1
  67. package/dist/chunks/{update-policy-BxvYMYz0.cjs → update-policy-BmiOd0PB.cjs} +1 -1
  68. package/dist/chunks/{update-policy-g0rCQ9BM.js → update-policy-hednMF-0.js} +1 -1
  69. package/dist/chunks/validators-BDYprKI9.cjs +1 -0
  70. package/dist/chunks/{validators-Cs74WVie.js → validators-DEmd8Sin.js} +1561 -1197
  71. package/dist/dashboard/index.cjs +1 -1
  72. package/dist/dashboard/index.js +2 -2
  73. package/dist/dashboard-authoring/index.cjs +3 -3
  74. package/dist/dashboard-authoring/index.js +35 -32
  75. package/dist/data-app-builder/index.cjs +1 -1
  76. package/dist/data-app-builder/index.js +2 -2
  77. package/dist/data-app-codegen/index.cjs +1 -1
  78. package/dist/data-app-codegen/index.js +2 -2
  79. package/dist/data-app-codegen-node/index.cjs +1 -1
  80. package/dist/data-app-codegen-node/index.js +3 -3
  81. package/dist/data-app-sdk/index.cjs +1 -1
  82. package/dist/data-app-sdk/index.js +78 -77
  83. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  84. package/dist/data-app-sdk-adapters/index.js +29 -30
  85. package/dist/data-app-sdk-validation/index.cjs +1 -1
  86. package/dist/data-app-sdk-validation/index.js +21 -21
  87. package/dist/format-utils/index.cjs +3 -3
  88. package/dist/format-utils/index.js +156 -140
  89. package/dist/index.cjs +1 -1
  90. package/dist/index.js +157 -155
  91. package/dist/report-runtime-context/index.cjs +1 -1
  92. package/dist/report-runtime-context/index.js +2 -2
  93. package/dist/style.css +1 -1
  94. package/dist/surfboard/index.cjs +1 -1
  95. package/dist/surfboard/index.js +3 -3
  96. package/dist/types/analytics-protocol.d.ts +81 -11
  97. package/dist/types/briefings.d.ts +727 -19
  98. package/dist/types/dashboard-assistant.d.ts +37 -17
  99. package/dist/types/dashboard-authoring.d.ts +61 -14
  100. package/dist/types/dashboard.d.ts +137 -12
  101. package/dist/types/data-app-builder.d.ts +28 -2
  102. package/dist/types/data-app-codegen-node.d.ts +29 -3
  103. package/dist/types/data-app-codegen.d.ts +29 -3
  104. package/dist/types/data-app-sdk-adapters.d.ts +28 -2
  105. package/dist/types/data-app-sdk-validation.d.ts +51 -7
  106. package/dist/types/data-app-sdk.d.ts +55 -10
  107. package/dist/types/format-utils.d.ts +190 -3
  108. package/dist/types/index.cjs +1 -1
  109. package/dist/types/index.js +4 -4
  110. package/dist/types/main.d.ts +128 -33
  111. package/dist/types/shared.d.ts +14 -12
  112. package/dist/types/surfboard.d.ts +138 -13
  113. package/dist/types/types.d.ts +117 -23
  114. package/dist/types/value-format-preferences.d.ts +3 -0
  115. package/package.json +2 -1
  116. package/dist/chunks/card-config-utils-15sRtebL.cjs +0 -1
  117. package/dist/chunks/card-config-utils-BYZ5MJOh.js +0 -16
  118. package/dist/chunks/catalog-field-grounding-Bnx-3tE0.cjs +0 -1
  119. package/dist/chunks/catalog-field-grounding-S2jKwKGD.js +0 -100
  120. package/dist/chunks/dashboard-briefing-launcher-DDgDr2s3.cjs +0 -26
  121. package/dist/chunks/dashboard-date-comparison-definition-DZq0htjG.cjs +0 -1
  122. package/dist/chunks/dashboard-input-contract-DSt8dGzP.js +0 -18
  123. package/dist/chunks/dashboard-input-contract-DV3cshjz.cjs +0 -1
  124. package/dist/chunks/dashboard-json-CYtvwtvj.cjs +0 -1
  125. package/dist/chunks/edit-dashboard-visual-DwKcvlsF.cjs +0 -177
  126. package/dist/chunks/editor-action-buttons-BVmsk0Aj.cjs +0 -16
  127. package/dist/chunks/format-types-CSv0V7mm.cjs +0 -1
  128. package/dist/chunks/format-types-DZGgYj39.js +0 -1663
  129. package/dist/chunks/index-CJdxSyQq.js +0 -2578
  130. package/dist/chunks/index-DPv8_Ild.cjs +0 -1395
  131. package/dist/chunks/index-DRlMUglg.cjs +0 -4
  132. package/dist/chunks/metric-comparison-97zHGEx5.js +0 -387
  133. package/dist/chunks/metric-comparison-CUAJ8n4y.cjs +0 -1
  134. package/dist/chunks/pivot-result-lifecycle-BBabQ_da.js +0 -914
  135. package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +0 -4
  136. package/dist/chunks/presentation-execution-BLfPTGX_.js +0 -637
  137. package/dist/chunks/presentation-execution-BTV-Q43g.cjs +0 -1
  138. package/dist/chunks/report-preferences-dialog-D9ZCGh9l.js +0 -691
  139. package/dist/chunks/report-preferences-dialog-DaqTEcac.cjs +0 -1
  140. package/dist/chunks/switch-Cjk6G06r.cjs +0 -138
  141. package/dist/chunks/temporal-bucket-BnPxGrAi.js +0 -446
  142. package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +0 -1
  143. package/dist/chunks/temporal-bucket-authoring-CgOuakGW.js +0 -205
  144. package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +0 -1
  145. package/dist/chunks/temporal-result-owner-6peubmhU.js +0 -443
  146. package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +0 -1
  147. package/dist/chunks/validators-9D4KBqKD.cjs +0 -1
@@ -0,0 +1,3714 @@
1
+ var Je = Object.defineProperty;
2
+ var Qe = (e, r, t) => r in e ? Je(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
+ var S = (e, r, t) => Qe(e, typeof r != "symbol" ? r + "" : r, t);
4
+ import { E as Xe, C as et, q as tt, D as rt, A as J, u as q, o as nt, M as ot, w as at, R as it, i as Te, b as ct, m as lt, P as U } from "./pivot-result-lifecycle-sjzIOpvp.js";
5
+ import { DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as de } from "../value-format-preferences/index.js";
6
+ import { n as dt, q as st, x as ae } from "./validators-DEmd8Sin.js";
7
+ import "./analyze-result-contract-BbRJ-C06.js";
8
+ import { h as $e, r as ke, a as Ee, v as mt, i as ut } from "./saved-temporal-bucket-format-SGAV0ivR.js";
9
+ import { r as z, b as ft, d as pt, P as yt } from "./pivot-result-identity-DU1v-5Xk.js";
10
+ import { v as ht, a as gt } from "./temporal-bucket-contract-D5d-xEl3.js";
11
+ import { f as vt, T as bt, k as xe, i as It } from "./temporal-bucket-5UYEotyQ.js";
12
+ import { r as Se, s as wt, i as Ct, a as Tt, b as $t, c as kt } from "./canonical-result-keys-D6avdjpA.js";
13
+ import "./temporal-bucket-authoring-K1kE6R_z.js";
14
+ import { v as _e } from "./raw-temporal-contract-CxncLze5.js";
15
+ const Et = `import pandas as pd
16
+ df = pd.DataFrame(data) # 'data' contains the query result
17
+ result = df.to_dict('records') # must return 'result' as [dict] type
18
+ `;
19
+ function vn(e) {
20
+ return {
21
+ databaseName: (e == null ? void 0 : e.lastSelectedDatabase) || "",
22
+ schemaName: (e == null ? void 0 : e.lastSelectedSchema) || "",
23
+ tableName: (e == null ? void 0 : e.lastSelectedTable) || "",
24
+ datamodelId: (e == null ? void 0 : e.datamodelId) || ""
25
+ };
26
+ }
27
+ function H(e) {
28
+ return e === Et ? "" : e;
29
+ }
30
+ function Q(e, r = e.config) {
31
+ return Se({
32
+ hasExecutableConfig: $e(r),
33
+ sql: e.sql,
34
+ normalizedPython: H(e.python || "")
35
+ });
36
+ }
37
+ class xt extends Error {
38
+ constructor(t) {
39
+ super(
40
+ `ambiguous_temporal_grain: Temporal field "${t}" has saved presentation but no valid grouping grain. Reconfigure and resave the field.`
41
+ );
42
+ S(this, "code", "ambiguous_temporal_grain");
43
+ S(this, "fieldId");
44
+ this.name = "AmbiguousGroupedTemporalGrainError", this.fieldId = t;
45
+ }
46
+ }
47
+ function St(e) {
48
+ return Ee(e) || e.semanticTemporalPresentation != null;
49
+ }
50
+ function _t(e) {
51
+ if (!e.id || !["date", "datetime"].includes(
52
+ dt(e.dataType)
53
+ ))
54
+ return;
55
+ if (st(e.granularity)) return e;
56
+ if (!St(e)) return;
57
+ if (!ke({
58
+ fieldId: e.id,
59
+ dataType: e.dataType,
60
+ granularity: e.granularity,
61
+ format: e.format,
62
+ dateFormat: e.dateFormat,
63
+ customFormat: e.customFormat
64
+ }).ok)
65
+ throw new xt(e.id);
66
+ return { ...e, granularity: "day" };
67
+ }
68
+ function se(e) {
69
+ const r = e.cardConfig ?? e.card.config;
70
+ if (!r || !e.supportsCardType(e.card.type) || Se({
71
+ hasExecutableConfig: $e(r),
72
+ sql: e.card.sql,
73
+ normalizedPython: H(e.card.python || "")
74
+ }) !== "config")
75
+ return;
76
+ const t = [
77
+ ...(r.groupByColumns || []).map((n) => ({
78
+ ...n,
79
+ role: "groupby"
80
+ })),
81
+ ...e.card.type === "pivotTable" ? (r.pivotByColumns || []).map((n) => ({
82
+ ...n,
83
+ role: "pivotby"
84
+ })) : []
85
+ ];
86
+ return {
87
+ cardType: e.card.type,
88
+ cardConfig: r,
89
+ fields: t.flatMap((n) => {
90
+ const o = _t(n);
91
+ return o ? [o] : [];
92
+ })
93
+ };
94
+ }
95
+ function bn(e) {
96
+ return se({
97
+ ...e,
98
+ supportsCardType: (r) => r === "table"
99
+ });
100
+ }
101
+ function In(e) {
102
+ return se({
103
+ ...e,
104
+ supportsCardType: Ct
105
+ });
106
+ }
107
+ function Ft(e) {
108
+ return se({
109
+ ...e,
110
+ // Raw detail-table presentation has its own result/adapter contract.
111
+ // This module remains grouped-only even though the shared producer
112
+ // registry now recognizes detailTable.
113
+ supportsCardType: (r) => r !== "detailTable" && wt(r)
114
+ });
115
+ }
116
+ const ve = /* @__PURE__ */ new WeakMap();
117
+ function Rt(e) {
118
+ const r = ve.get(e);
119
+ if (r) return r;
120
+ const t = Xe(e);
121
+ return ve.set(e, t), t;
122
+ }
123
+ function L(e, r) {
124
+ const t = e ?? [], n = r ?? [];
125
+ return t.length === n.length && t.every((o, a) => o === n[a]);
126
+ }
127
+ function At(e, r) {
128
+ const t = et({
129
+ groupByFields: r.groupByColumns,
130
+ metricFields: r.metricColumns,
131
+ pivotByFields: r.pivotByColumns,
132
+ detailFields: r.detailColumns
133
+ });
134
+ return L(
135
+ e.expectedRoleFieldIds.groupby,
136
+ t.expectedRoleFieldIds.groupby
137
+ ) && L(
138
+ e.expectedRoleFieldIds.metric,
139
+ t.expectedRoleFieldIds.metric
140
+ ) && L(
141
+ e.expectedRoleFieldIds.pivotby,
142
+ t.expectedRoleFieldIds.pivotby
143
+ ) && L(
144
+ e.expectedRoleFieldIds.detail,
145
+ t.expectedRoleFieldIds.detail
146
+ ) && L(
147
+ e.expectedMetricAliases,
148
+ t.expectedMetricAliases
149
+ );
150
+ }
151
+ class Bt extends Error {
152
+ constructor(t) {
153
+ super(
154
+ `missing_resolved_temporal_format: Saved presentation is missing temporal field "${t.fieldId}" for card "${t.cardId}". Resave the report or Briefing to capture the current dashboard presentation.`
155
+ );
156
+ S(this, "code", "missing_resolved_temporal_format");
157
+ S(this, "deliveryBlocking", !0);
158
+ S(this, "dashboardId");
159
+ S(this, "cardId");
160
+ S(this, "fieldId");
161
+ this.name = "MissingResolvedTemporalPresentationError", this.dashboardId = t.dashboardId, this.cardId = t.cardId, this.fieldId = t.fieldId;
162
+ }
163
+ }
164
+ class ee extends Error {
165
+ constructor(t) {
166
+ super(
167
+ `missing_temporal_bucket_metadata: Result column "${t.columnKey}" is missing temporal bucket metadata for field "${t.fieldId}" on card "${t.cardId}". Refresh the report and resave the delivery if the problem persists.`
168
+ );
169
+ S(this, "code", "missing_temporal_bucket_metadata");
170
+ S(this, "deliveryBlocking", !0);
171
+ S(this, "cardId");
172
+ S(this, "fieldId");
173
+ S(this, "columnKey");
174
+ this.name = "MissingTemporalResultMetadataError", this.cardId = t.cardId, this.fieldId = t.fieldId, this.columnKey = t.columnKey;
175
+ }
176
+ }
177
+ class K extends Error {
178
+ constructor(t, n, o) {
179
+ super(`${t}: ${n}`);
180
+ S(this, "deliveryBlocking", !0);
181
+ this.code = t, this.context = o, this.name = "DashboardTemporalBoundaryError";
182
+ }
183
+ }
184
+ function Fe(e, r) {
185
+ return `${r}:${e}`;
186
+ }
187
+ function Pt(e) {
188
+ var r, t;
189
+ return (t = (r = e.presentation) == null ? void 0 : r.byFieldRole) == null ? void 0 : t.get(
190
+ Fe(e.fieldId, e.role)
191
+ );
192
+ }
193
+ function Mt(e) {
194
+ var t;
195
+ if ((((t = e.cardConfig.metricColumns) == null ? void 0 : t.length) || 0) > 0 || e.binding.role !== "metric")
196
+ return !1;
197
+ const r = e.binding.outputKey || e.binding.rawKey;
198
+ return e.columns.some(
199
+ (n) => {
200
+ var o;
201
+ return n.role === "measure" && n.dataType === "number" && (n.key === r || ((o = n.pivotIdentity) == null ? void 0 : o.metricId) === ae);
202
+ }
203
+ );
204
+ }
205
+ function wn(e, r) {
206
+ return !r || r.byColumnKey.size === 0 ? e.map((t) => ({ ...t })) : e.map((t) => {
207
+ const n = { ...t };
208
+ return r.byColumnKey.forEach((o, a) => {
209
+ Object.prototype.hasOwnProperty.call(t, a) && (n[a] = Re({
210
+ value: t[a],
211
+ presentation: o
212
+ }));
213
+ }), n;
214
+ });
215
+ }
216
+ function Cn(e) {
217
+ var p;
218
+ if (!e.result || typeof e.result != "object") return !1;
219
+ const r = e.result;
220
+ if (e.expectedResultOwner !== void 0 && r.resultOwner !== e.expectedResultOwner)
221
+ return !1;
222
+ const t = e.activation;
223
+ if (!t || t.cardType !== "pivotTable" && t.fields.length === 0)
224
+ return !0;
225
+ const n = Array.isArray(r.records) ? r.records.length : void 0, o = (t.cardConfig.pivotByColumns || []).map((d) => d.id);
226
+ if (t.cardType === "pivotTable")
227
+ try {
228
+ const d = Rt(r);
229
+ if (!At(
230
+ d.pivotResultContract,
231
+ t.cardConfig
232
+ ))
233
+ return !1;
234
+ if (d.pivotResultState === "loaded_empty") return !0;
235
+ const v = d.columns.filter(
236
+ (w) => d.pivotResultContract.columnKinds[w.key] === "pivot_metric"
237
+ ), h = v.filter(
238
+ (w) => {
239
+ var g;
240
+ return (((g = w.pivotIdentity) == null ? void 0 : g.members.length) ?? 0) > 0;
241
+ }
242
+ ), I = v.length > 0 && v.every(
243
+ (w) => {
244
+ var g;
245
+ return ((g = w.pivotIdentity) == null ? void 0 : g.members.length) === 0 && ft({
246
+ expectedPivotFieldIds: o,
247
+ classification: d.pivotResultContract.columnClassifications[w.key]
248
+ });
249
+ }
250
+ );
251
+ return t.fields.every((w) => {
252
+ var E;
253
+ const g = z(
254
+ d.columnKeyMap,
255
+ w.id,
256
+ w.role
257
+ );
258
+ if (!g) return !1;
259
+ if (g.role === "pivotby") {
260
+ const F = h.flatMap(
261
+ (O) => {
262
+ var V;
263
+ return ((V = O.pivotIdentity) == null ? void 0 : V.members.filter(
264
+ (Ze) => Ze.fieldId === w.id
265
+ )) ?? [];
266
+ }
267
+ );
268
+ return F.length === 0 ? I : F.every(
269
+ (O) => {
270
+ var V;
271
+ return ((V = O.temporalBucket) == null ? void 0 : V.granularity) === w.granularity;
272
+ }
273
+ );
274
+ }
275
+ const $ = d.columns.find(
276
+ (F) => F.key === (g.outputKey || g.rawKey)
277
+ );
278
+ return ((E = $ == null ? void 0 : $.temporalBucket) == null ? void 0 : E.granularity) === w.granularity;
279
+ });
280
+ } catch (d) {
281
+ if (d instanceof rt) return !1;
282
+ throw d;
283
+ }
284
+ if (n === 0)
285
+ return !0;
286
+ const a = r.columnKeyMap;
287
+ if (!a || !a.byRole || typeof a.byRole != "object" || Array.isArray(a.byRole))
288
+ return !1;
289
+ const i = [
290
+ ...(t.cardConfig.groupByColumns || []).map((d) => ({
291
+ field: d,
292
+ role: "groupby"
293
+ })),
294
+ ...(t.cardConfig.metricColumns || []).map((d) => ({
295
+ field: d,
296
+ role: "metric"
297
+ })),
298
+ ...(t.cardConfig.pivotByColumns || []).map((d) => ({
299
+ field: d,
300
+ role: "pivotby"
301
+ })),
302
+ ...(t.cardConfig.detailColumns || []).map((d) => ({
303
+ field: d,
304
+ role: "detail"
305
+ }))
306
+ ], l = new Set(
307
+ i.map(({ field: d, role: v }) => `${v}:${d.id}`)
308
+ ), m = new Map(
309
+ (r.columns || []).map((d) => [d.key, d])
310
+ ), c = z(
311
+ a,
312
+ ae,
313
+ "metric"
314
+ );
315
+ if (c) {
316
+ if (!Mt({
317
+ cardConfig: t.cardConfig,
318
+ binding: c,
319
+ columns: r.columns || []
320
+ }))
321
+ return !1;
322
+ l.add(`metric:${ae}`);
323
+ }
324
+ const s = Object.entries(a.byRole).flatMap(
325
+ ([d, v]) => Object.keys(v || {}).map((h) => `${d}:${h}`)
326
+ );
327
+ if (s.length !== l.size || s.some((d) => !l.has(d)) || i.some(
328
+ ({ field: d, role: v }) => !z(a, d.id, v)
329
+ ))
330
+ return !1;
331
+ try {
332
+ pt(
333
+ (r.columns || []).map((d) => ({
334
+ key: d.key,
335
+ pivotIdentity: d.pivotIdentity
336
+ })),
337
+ {
338
+ expectedPivotFieldIds: o,
339
+ columnClassifications: r.columnMetadata
340
+ }
341
+ );
342
+ } catch (d) {
343
+ if (d instanceof yt) return !1;
344
+ throw d;
345
+ }
346
+ const u = (r.columns || []).filter((d) => {
347
+ const v = d.pivotIdentity;
348
+ return !!(v && v.members.length > 0);
349
+ });
350
+ return n !== 0 && ((p = t.cardConfig.pivotByColumns) != null && p.length) && u.length === 0 ? !1 : t.fields.every((d) => {
351
+ var I;
352
+ const v = z(
353
+ a,
354
+ d.id,
355
+ d.role
356
+ );
357
+ if (!v) return !1;
358
+ if (v.role === "pivotby") {
359
+ const g = u.flatMap(
360
+ ($) => {
361
+ var E;
362
+ return ((E = $.pivotIdentity) == null ? void 0 : E.members) ?? [];
363
+ }
364
+ ).filter(($) => $.fieldId === d.id);
365
+ return u.length === 0 ? n === 0 : g.length > 0 && g.every(
366
+ ($) => {
367
+ var E;
368
+ return ((E = $.temporalBucket) == null ? void 0 : E.granularity) === d.granularity;
369
+ }
370
+ );
371
+ }
372
+ const h = m.get(v.outputKey || v.rawKey);
373
+ return ((I = h == null ? void 0 : h.temporalBucket) == null ? void 0 : I.granularity) === d.granularity;
374
+ });
375
+ }
376
+ function Z(e, r) {
377
+ const t = e.semanticTemporalPresentation, n = r === "card" ? {
378
+ format: e.format,
379
+ dateFormat: e.dateFormat
380
+ } : { format: t == null ? void 0 : t.format };
381
+ if (!Ee(n))
382
+ return;
383
+ const o = ke({
384
+ fieldId: e.id,
385
+ dataType: e.dataType,
386
+ granularity: r === "semantic" ? t == null ? void 0 : t.granularity : e.granularity,
387
+ ...r === "card" ? {
388
+ format: e.format,
389
+ dateFormat: e.dateFormat,
390
+ customFormat: e.customFormat
391
+ } : { format: t == null ? void 0 : t.format }
392
+ });
393
+ if (!o.ok) throw new Error(o.error.code);
394
+ return o.format;
395
+ }
396
+ function Dt(e, r, t = de) {
397
+ const n = Z(e, "card"), o = Z(e, "semantic"), a = e.semanticTemporalPresentation;
398
+ return xe({
399
+ metadata: r,
400
+ ...n ? { cardFormat: n } : {},
401
+ ...o && a ? {
402
+ semanticFormat: {
403
+ granularity: a.granularity,
404
+ format: o
405
+ }
406
+ } : {},
407
+ locale: t.locale,
408
+ styles: {
409
+ dateStyle: t.dateStyle,
410
+ dateTime: t.dateTime
411
+ }
412
+ });
413
+ }
414
+ function Ot(e, r = It, t = "en-US") {
415
+ var i;
416
+ const n = Z(e, "card"), o = ((i = e.semanticTemporalPresentation) == null ? void 0 : i.granularity) === e.granularity ? Z(e, "semantic") : void 0, a = n && n.presentation.mode !== "auto" ? n : o && o.presentation.mode !== "auto" ? o : {
417
+ presentation: { mode: "auto" }
418
+ };
419
+ return a.presentation.mode === "auto" ? {
420
+ type: "temporal_bucket",
421
+ locale: t,
422
+ presentation: { mode: "auto", styles: r }
423
+ } : {
424
+ type: "temporal_bucket",
425
+ locale: t,
426
+ presentation: a.presentation
427
+ };
428
+ }
429
+ function Tn(e) {
430
+ const r = e.activation;
431
+ if (!r)
432
+ return {
433
+ byColumnKey: /* @__PURE__ */ new Map(),
434
+ byFieldId: /* @__PURE__ */ new Map(),
435
+ byFieldRole: /* @__PURE__ */ new Map()
436
+ };
437
+ if (e.resultRowCount === 0)
438
+ return {
439
+ byColumnKey: /* @__PURE__ */ new Map(),
440
+ byFieldId: /* @__PURE__ */ new Map(),
441
+ byFieldRole: /* @__PURE__ */ new Map()
442
+ };
443
+ const t = new Map(
444
+ (e.columns || []).map((c) => [c.key, c])
445
+ ), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), i = r.fields.reduce((c, s) => (c.set(s.id, (c.get(s.id) || 0) + 1), c), /* @__PURE__ */ new Map()), l = (c, s) => {
446
+ a.set(
447
+ Fe(c.id, c.role),
448
+ s
449
+ ), i.get(c.id) === 1 && o.set(c.id, s);
450
+ }, m = (c, s, u) => {
451
+ if (s.granularity !== c.granularity)
452
+ throw new K(
453
+ "invalid_temporal_bucket_metadata",
454
+ `Result identity "${u}" declares ${s.granularity} buckets for active ${c.granularity} field "${c.id}".`,
455
+ { cardId: e.card.id, fieldId: c.id, columnKey: u }
456
+ );
457
+ const p = e.executionSnapshot && e.dashboardId ? tt({
458
+ snapshot: e.executionSnapshot,
459
+ scope: {
460
+ dashboardId: e.dashboardId,
461
+ cardId: e.card.id,
462
+ ...e.attachmentIndex !== void 0 ? { attachmentIndex: e.attachmentIndex } : {}
463
+ },
464
+ target: {
465
+ kind: "field",
466
+ fieldId: c.id,
467
+ role: c.role
468
+ }
469
+ }) : void 0;
470
+ if (e.executionSnapshot && !p)
471
+ throw new Bt({
472
+ dashboardId: e.dashboardId,
473
+ cardId: e.card.id,
474
+ fieldId: c.id
475
+ });
476
+ return {
477
+ columnKey: u,
478
+ fieldId: c.id,
479
+ role: c.role,
480
+ metadata: s,
481
+ resolved: p ? xe({
482
+ metadata: s,
483
+ cardFormat: p,
484
+ locale: p.locale,
485
+ ...p.presentation.mode === "auto" ? {
486
+ styles: p.presentation.styles
487
+ } : {}
488
+ }) : Dt(
489
+ c,
490
+ s,
491
+ e.valueFormatPreferences ?? de
492
+ )
493
+ };
494
+ };
495
+ for (const c of r.fields) {
496
+ const s = z(
497
+ e.columnKeyMap,
498
+ c.id,
499
+ c.role
500
+ );
501
+ if (!s) {
502
+ if (e.columns === void 0 && e.columnKeyMap === void 0 && (e.resultRowCount === void 0 || e.resultRowCount === 0))
503
+ continue;
504
+ throw new K(
505
+ "missing_temporal_column_binding",
506
+ `Activated temporal field "${c.id}" has no authoritative result-column binding.`,
507
+ { cardId: e.card.id, fieldId: c.id, columnKey: c.name }
508
+ );
509
+ }
510
+ if (s.role === "pivotby") {
511
+ const h = (e.columns || []).filter(
512
+ (E) => E.pivotIdentity !== void 0
513
+ ), I = h.flatMap(
514
+ (E) => {
515
+ var F;
516
+ return (((F = E.pivotIdentity) == null ? void 0 : F.members) || []).filter((O) => O.fieldId === c.id).map((O) => ({ column: E, member: O }));
517
+ }
518
+ );
519
+ if (I.length === 0) {
520
+ if (h.length === 0 && (e.card.type !== "pivotTable" || e.resultRowCount === 0))
521
+ continue;
522
+ throw new ee({
523
+ cardId: e.card.id,
524
+ fieldId: c.id,
525
+ columnKey: s.outputKey || s.rawKey
526
+ });
527
+ }
528
+ const w = I[0];
529
+ if (!w.member.temporalBucket)
530
+ throw new ee({
531
+ cardId: e.card.id,
532
+ fieldId: c.id,
533
+ columnKey: w.column.key
534
+ });
535
+ const g = ht(
536
+ w.member.temporalBucket
537
+ );
538
+ if (!g.ok || !g.value)
539
+ throw new K(
540
+ "invalid_temporal_bucket_metadata",
541
+ g.ok ? `Pivot result column "${w.column.key}" has no validated temporal bucket metadata.` : g.error.message,
542
+ {
543
+ cardId: e.card.id,
544
+ fieldId: c.id,
545
+ columnKey: w.column.key
546
+ }
547
+ );
548
+ const $ = m(
549
+ c,
550
+ g.value,
551
+ w.column.key
552
+ );
553
+ for (const { column: E, member: F } of I)
554
+ if (!F.temporalBucket || JSON.stringify(F.temporalBucket) !== JSON.stringify(w.member.temporalBucket))
555
+ throw new K(
556
+ "invalid_temporal_bucket_metadata",
557
+ `Pivot result column "${E.key}" has contradictory bucket metadata for field "${c.id}".`,
558
+ { cardId: e.card.id, fieldId: c.id, columnKey: E.key }
559
+ );
560
+ l(c, $);
561
+ continue;
562
+ }
563
+ const u = s.outputKey || s.rawKey, p = t.get(u);
564
+ if (!(p != null && p.temporalBucket))
565
+ throw new ee({
566
+ cardId: e.card.id,
567
+ fieldId: c.id,
568
+ columnKey: u
569
+ });
570
+ const d = gt(p, {
571
+ metadataRequired: !0
572
+ });
573
+ if (!d.ok || !d.value)
574
+ throw new K(
575
+ "invalid_temporal_bucket_metadata",
576
+ d.ok ? `Result column "${u}" has no validated temporal bucket metadata.` : d.error.message,
577
+ { cardId: e.card.id, fieldId: c.id, columnKey: u }
578
+ );
579
+ const v = m(
580
+ c,
581
+ d.value,
582
+ u
583
+ );
584
+ n.set(u, v), l(c, v);
585
+ }
586
+ return { byColumnKey: n, byFieldId: o, byFieldRole: a };
587
+ }
588
+ function $n(e) {
589
+ var t, n;
590
+ const r = e.role ? Pt({
591
+ presentation: e.presentation,
592
+ fieldId: e.fieldId,
593
+ role: e.role
594
+ }) : (n = (t = e.presentation) == null ? void 0 : t.byFieldId) == null ? void 0 : n.get(e.fieldId);
595
+ return r ? Re({
596
+ value: e.value,
597
+ presentation: r
598
+ }) : e.value === null || e.value === void 0 ? "" : String(e.value);
599
+ }
600
+ function Re(e) {
601
+ if (e.value === null || e.value === void 0) return "(Blank)";
602
+ if (typeof e.value != "string")
603
+ throw new K(
604
+ "invalid_temporal_bucket_value",
605
+ `Canonical temporal column "${e.presentation.columnKey}" must contain a string or null.`,
606
+ {
607
+ fieldId: e.presentation.fieldId,
608
+ columnKey: e.presentation.columnKey
609
+ }
610
+ );
611
+ try {
612
+ return vt({
613
+ value: e.value,
614
+ metadata: e.presentation.metadata,
615
+ format: e.presentation.resolved.format
616
+ });
617
+ } catch (r) {
618
+ throw r instanceof bt ? new K(
619
+ r.code,
620
+ r.message,
621
+ {
622
+ fieldId: e.presentation.fieldId,
623
+ columnKey: e.presentation.columnKey
624
+ }
625
+ ) : r;
626
+ }
627
+ }
628
+ class x extends Error {
629
+ constructor(r, t, n) {
630
+ super(`${r}: ${t}`), this.code = r, this.context = n, Object.setPrototypeOf(this, x.prototype), this.name = "RawTemporalPresentationBoundaryError";
631
+ }
632
+ }
633
+ function Ae() {
634
+ return { type: "raw_temporal", presentation: { mode: "auto" } };
635
+ }
636
+ function Kt(e) {
637
+ if (e.locale || e.relative || e.timezone && e.timezone !== "auto" || e.sourceTimezone && e.sourceTimezone !== "auto" || e.prefix || e.suffix)
638
+ throw new x(
639
+ "invalid_raw_temporal_format",
640
+ "Activated raw temporal presentation contains unsupported locale, relative-time, timezone, prefix, or suffix settings."
641
+ );
642
+ }
643
+ function Be(e) {
644
+ const r = e.format;
645
+ if ((r == null ? void 0 : r.type) === "date" && (Kt(r), r.pattern))
646
+ return {
647
+ type: "raw_temporal",
648
+ presentation: {
649
+ mode: "pattern",
650
+ dialect: "semaphor_tokens",
651
+ pattern: r.pattern
652
+ }
653
+ };
654
+ if (r)
655
+ throw new x(
656
+ "invalid_raw_temporal_format",
657
+ `Raw temporal detail field "${e.id}" has an incompatible authored format.`,
658
+ { fieldId: e.id }
659
+ );
660
+ if (e.dateFormat === "custom") {
661
+ if (!e.customFormat)
662
+ throw new x(
663
+ "invalid_raw_temporal_format",
664
+ `Raw temporal detail field "${e.id}" selects a custom pattern but has no customFormat.`,
665
+ { fieldId: e.id }
666
+ );
667
+ return {
668
+ type: "raw_temporal",
669
+ presentation: {
670
+ mode: "pattern",
671
+ dialect: "semaphor_tokens",
672
+ pattern: e.customFormat
673
+ }
674
+ };
675
+ }
676
+ return e.dateFormat ? {
677
+ type: "raw_temporal",
678
+ presentation: {
679
+ mode: "pattern",
680
+ dialect: "semaphor_tokens",
681
+ pattern: e.dateFormat
682
+ }
683
+ } : Ae();
684
+ }
685
+ function me(e) {
686
+ if (e != null && e.useRelativeTime) return;
687
+ if (!e) return Ae();
688
+ if (e.useCustomFormat && !e.customFormat)
689
+ throw new x(
690
+ "invalid_raw_temporal_format",
691
+ "Declared SQL temporal presentation selects a custom pattern but has no customFormat."
692
+ );
693
+ const r = e.useCustomFormat && e.customFormat ? e.customFormat : e.format, t = e.timezone, n = e.sourceTimezone, o = t && t !== "auto" ? { timezone: t } : void 0, a = {
694
+ sourceTimezone: n && n !== "auto" ? n : "UTC"
695
+ };
696
+ return r ? {
697
+ type: "raw_temporal",
698
+ ...o,
699
+ ...a,
700
+ presentation: {
701
+ mode: "pattern",
702
+ dialect: "date_fns",
703
+ pattern: r
704
+ }
705
+ } : {
706
+ type: "raw_temporal",
707
+ ...o,
708
+ ...a,
709
+ presentation: { mode: "auto" }
710
+ };
711
+ }
712
+ function kn(e) {
713
+ const r = me(e.settings);
714
+ if (!r)
715
+ throw new x(
716
+ "invalid_raw_temporal_format",
717
+ "Relative-time SQL presentation does not have an absolute date preview."
718
+ );
719
+ const t = e.valueKind ?? "date", n = {
720
+ kind: "raw_temporal",
721
+ valueKind: t
722
+ }, o = e.value ?? (t === "date" ? "2023-05-15" : t === "wall_datetime" ? "2023-05-15T14:30:45" : "2023-05-15T14:30:45Z"), a = J({
723
+ metadata: n,
724
+ format: q({
725
+ format: r,
726
+ preferences: e.preferences,
727
+ calendar: { tz: e.calendarTimezone }
728
+ })
729
+ })(o);
730
+ if (!a.ok)
731
+ throw new x(
732
+ "invalid_raw_temporal_format",
733
+ a.diagnostic.message
734
+ );
735
+ return a.text;
736
+ }
737
+ function Nt(e) {
738
+ var t;
739
+ const r = e.effectiveCardConfig ?? e.card.config;
740
+ return Q(e.card, r) === "freeform" && !!((t = e.card.sql) != null && t.trim()) && !H(e.card.python || "").trim();
741
+ }
742
+ function zt() {
743
+ return {
744
+ activatedColumnKeys: /* @__PURE__ */ new Set(),
745
+ byColumnKey: /* @__PURE__ */ new Map(),
746
+ byFieldId: /* @__PURE__ */ new Map()
747
+ };
748
+ }
749
+ function ue(e) {
750
+ var r;
751
+ return e.cardType === "detailTable" && e.resultOwner === "config" ? (((r = e.effectiveCardConfig) == null ? void 0 : r.detailColumns) || []).filter(
752
+ (t) => t.dateValueMode === "canonical"
753
+ ) : [];
754
+ }
755
+ function ie(e, r) {
756
+ return e === void 0 ? { kind: "invalid", error: r } : {
757
+ kind: "invalid",
758
+ error: e instanceof x ? e : e instanceof it ? new x(
759
+ e.code,
760
+ e.message,
761
+ r.context
762
+ ) : new x(
763
+ r.code,
764
+ e instanceof Error ? e.message : r.message,
765
+ r.context
766
+ )
767
+ };
768
+ }
769
+ function Vt(e) {
770
+ const r = ue(e);
771
+ if (r.length === 0) return { kind: "inactive" };
772
+ if (!e.result) return { kind: "loading" };
773
+ const { records: t, columns: n, columnKeyMap: o } = e.result;
774
+ if (!Array.isArray(t) || !Array.isArray(n) || !o)
775
+ return ie(
776
+ void 0,
777
+ new x(
778
+ "missing_raw_temporal_result_contract",
779
+ "Activated raw temporal detail results require records, columns, and columnKeyMap atomically."
780
+ )
781
+ );
782
+ try {
783
+ const a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
784
+ for (const m of r) {
785
+ const c = z(
786
+ o,
787
+ m.id,
788
+ "detail"
789
+ );
790
+ if (!c || c.role !== "detail" || typeof c.rawKey != "string" || c.rawKey.trim().length === 0 || c.outputKey !== void 0 && (typeof c.outputKey != "string" || c.outputKey.trim().length === 0))
791
+ throw new x(
792
+ "missing_raw_temporal_column_binding",
793
+ `Raw temporal detail field "${m.id}" has no valid exact detail result binding.`,
794
+ { fieldId: m.id }
795
+ );
796
+ const s = c.outputKey ?? c.rawKey, u = n.find((h) => h.key === s);
797
+ if (!u)
798
+ throw new x(
799
+ "missing_raw_temporal_result_contract",
800
+ `Raw temporal result column "${s}" is absent.`,
801
+ { fieldId: m.id, columnKey: s }
802
+ );
803
+ const p = _e(u, {
804
+ metadataRequired: !0
805
+ });
806
+ if (!p)
807
+ throw new x(
808
+ "invalid_raw_temporal_metadata",
809
+ `Raw temporal result column "${s}" has no metadata.`,
810
+ { fieldId: m.id, columnKey: s }
811
+ );
812
+ const d = q({
813
+ format: Be(m),
814
+ preferences: e.preferences,
815
+ calendar: e.calendar
816
+ }), v = {
817
+ fieldId: m.id,
818
+ columnKey: s,
819
+ metadata: p,
820
+ format: d,
821
+ formatValue: J({ metadata: p, format: d })
822
+ };
823
+ for (let h = 0; h < t.length; h += 1)
824
+ if (!Object.prototype.hasOwnProperty.call(t[h], s) || t[h][s] === void 0)
825
+ throw new x(
826
+ "missing_raw_temporal_result_contract",
827
+ `Raw temporal result row ${h} is missing column "${s}".`,
828
+ { fieldId: m.id, columnKey: s }
829
+ );
830
+ a.set(s, v), i.set(m.id, v);
831
+ }
832
+ const l = {
833
+ activatedColumnKeys: new Set(a.keys()),
834
+ byColumnKey: a,
835
+ byFieldId: i
836
+ };
837
+ return t.length === 0 ? { kind: "loaded_empty", presentation: l } : { kind: "loaded_valid", presentation: l };
838
+ } catch (a) {
839
+ return ie(
840
+ a,
841
+ new x(
842
+ "invalid_raw_temporal_metadata",
843
+ "Activated raw temporal result metadata is invalid."
844
+ )
845
+ );
846
+ }
847
+ }
848
+ function Lt(e) {
849
+ var n, o;
850
+ const r = e.effectiveCardConfig ?? e.card.config, t = Q(
851
+ e.card,
852
+ r
853
+ );
854
+ return e.card.type === "detailTable" && t === "config" ? ue({
855
+ cardType: e.card.type,
856
+ resultOwner: t,
857
+ effectiveCardConfig: r
858
+ }).length > 0 && e.records !== void 0 && (!e.columns || !e.columnKeyMap) ? {
859
+ kind: "invalid",
860
+ error: new x(
861
+ "missing_raw_temporal_result_contract",
862
+ "Activated raw temporal detail results require records, columns, and columnKeyMap atomically."
863
+ )
864
+ } : be(
865
+ Vt({
866
+ cardType: e.card.type,
867
+ resultOwner: t,
868
+ effectiveCardConfig: r,
869
+ result: e.records === void 0 || !e.columns || !e.columnKeyMap ? void 0 : {
870
+ records: e.records,
871
+ columns: e.columns,
872
+ columnKeyMap: e.columnKeyMap
873
+ },
874
+ preferences: e.preferences,
875
+ calendar: e.calendar
876
+ }),
877
+ e
878
+ ) : be(
879
+ jt({
880
+ resultOwner: t,
881
+ sql: e.card.sql,
882
+ normalizedPython: H(
883
+ e.card.python || ""
884
+ ),
885
+ records: e.records,
886
+ columns: e.columns,
887
+ columnSettings: (o = (n = e.card.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.columnSettingsMap,
888
+ preferences: e.preferences,
889
+ calendar: e.calendar
890
+ }),
891
+ e
892
+ );
893
+ }
894
+ function Ut(e) {
895
+ var n, o;
896
+ const r = e.effectiveCardConfig ?? e.card.config, t = Q(
897
+ e.card,
898
+ r
899
+ );
900
+ return ue({
901
+ cardType: e.card.type,
902
+ resultOwner: t,
903
+ effectiveCardConfig: r
904
+ }).length > 0 ? !0 : Nt(e) ? Object.values(
905
+ ((o = (n = e.card.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.columnSettingsMap) || {}
906
+ ).some(
907
+ (a) => {
908
+ var i;
909
+ return a.type === "date" && !((i = a.dateFormat) != null && i.useRelativeTime);
910
+ }
911
+ ) : !1;
912
+ }
913
+ function be(e, r) {
914
+ if (!r.executionSnapshot || e.kind === "inactive" || e.kind === "loading" || e.kind === "invalid")
915
+ return e;
916
+ if (!r.dashboardId)
917
+ return {
918
+ kind: "invalid",
919
+ error: new x(
920
+ "missing_raw_temporal_result_contract",
921
+ "A dashboard ID is required to resolve the captured raw temporal presentation."
922
+ )
923
+ };
924
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
925
+ for (const o of e.presentation.activatedColumnKeys) {
926
+ const a = nt({
927
+ snapshot: r.executionSnapshot,
928
+ scope: {
929
+ dashboardId: r.dashboardId,
930
+ cardId: r.card.id,
931
+ ...r.attachmentIndex !== void 0 ? { attachmentIndex: r.attachmentIndex } : {}
932
+ },
933
+ target: { kind: "column", columnKey: o }
934
+ });
935
+ if (!a)
936
+ return {
937
+ kind: "invalid",
938
+ error: new ot(o)
939
+ };
940
+ const i = e.presentation.byColumnKey.get(o);
941
+ if (!i) continue;
942
+ const l = {
943
+ ...i,
944
+ format: a,
945
+ formatValue: J({
946
+ metadata: i.metadata,
947
+ format: a
948
+ })
949
+ };
950
+ t.set(i.columnKey, l), i.fieldId && n.set(i.fieldId, l);
951
+ }
952
+ return {
953
+ ...e,
954
+ presentation: {
955
+ activatedColumnKeys: e.presentation.activatedColumnKeys,
956
+ byColumnKey: t,
957
+ byFieldId: n
958
+ }
959
+ };
960
+ }
961
+ function jt(e) {
962
+ var t, n;
963
+ if (e.resultOwner !== "freeform" || !((t = e.sql) != null && t.trim()) || (n = e.normalizedPython) != null && n.trim())
964
+ return { kind: "inactive" };
965
+ const r = Object.entries(
966
+ e.columnSettings || {}
967
+ ).filter(
968
+ ([, o]) => {
969
+ var a;
970
+ return o.type === "date" && !((a = o.dateFormat) != null && a.useRelativeTime);
971
+ }
972
+ );
973
+ if (r.length === 0) return { kind: "inactive" };
974
+ if (!e.records) return { kind: "loading" };
975
+ try {
976
+ const o = /* @__PURE__ */ new Map(), a = new Set(
977
+ r.map(([c]) => c)
978
+ ), i = /* @__PURE__ */ new Map(), l = [...e.columns || []];
979
+ for (const [c, s] of r) {
980
+ const u = me(
981
+ s.dateFormat
982
+ );
983
+ if (!u) continue;
984
+ const p = at({
985
+ columnKey: c,
986
+ values: e.records.map((I) => {
987
+ if (!Object.prototype.hasOwnProperty.call(I, c))
988
+ throw new x(
989
+ "missing_raw_temporal_result_contract",
990
+ `Declared SQL temporal column "${c}" is absent from a physical result row.`,
991
+ { columnKey: c }
992
+ );
993
+ const w = I[c];
994
+ return w === null || typeof w == "string" ? w : String(w);
995
+ })
996
+ });
997
+ if (i.set(c, p), p.status !== "classified") continue;
998
+ let d = l.findIndex(
999
+ (I) => I.key === c
1000
+ );
1001
+ if (e.columns && d < 0)
1002
+ throw new x(
1003
+ "missing_raw_temporal_result_contract",
1004
+ `Classified SQL temporal column "${c}" is absent from result columns.`,
1005
+ { columnKey: c }
1006
+ );
1007
+ d < 0 && (d = l.length, l.push({
1008
+ key: c,
1009
+ name: c,
1010
+ label: c,
1011
+ role: "dimension",
1012
+ dataType: "string"
1013
+ }));
1014
+ const v = {
1015
+ ...l[d],
1016
+ role: "date",
1017
+ dataType: p.metadata.valueKind === "date" ? "date" : "datetime",
1018
+ rawTemporal: p.metadata
1019
+ };
1020
+ _e(v, {
1021
+ metadataRequired: !0
1022
+ }), l[d] = v;
1023
+ const h = q({
1024
+ format: u,
1025
+ preferences: e.preferences,
1026
+ calendar: e.calendar
1027
+ });
1028
+ o.set(c, {
1029
+ columnKey: c,
1030
+ metadata: p.metadata,
1031
+ format: h,
1032
+ formatValue: J({
1033
+ metadata: p.metadata,
1034
+ format: h
1035
+ })
1036
+ });
1037
+ }
1038
+ const m = {
1039
+ ...zt(),
1040
+ activatedColumnKeys: a,
1041
+ byColumnKey: o
1042
+ };
1043
+ return e.records.length === 0 ? {
1044
+ kind: "loaded_empty",
1045
+ presentation: m,
1046
+ adaptedColumns: l,
1047
+ sqlClassifications: i
1048
+ } : {
1049
+ kind: "loaded_valid",
1050
+ presentation: m,
1051
+ adaptedColumns: l,
1052
+ sqlClassifications: i
1053
+ };
1054
+ } catch (o) {
1055
+ return ie(
1056
+ o,
1057
+ new x(
1058
+ "invalid_raw_temporal_format",
1059
+ "Declared SQL raw temporal presentation is invalid."
1060
+ )
1061
+ );
1062
+ }
1063
+ }
1064
+ function En(e) {
1065
+ if (e.value !== null && typeof e.value != "string")
1066
+ return {
1067
+ value: e.value,
1068
+ label: String(e.value),
1069
+ result: {
1070
+ ok: !1,
1071
+ text: String(e.value),
1072
+ diagnostic: {
1073
+ code: "invalid_raw_temporal_value",
1074
+ message: `Raw temporal column "${e.presentation.columnKey}" must contain a string or null.`
1075
+ }
1076
+ }
1077
+ };
1078
+ const r = e.presentation.formatValue(e.value);
1079
+ return { value: e.value, label: r.text, result: r };
1080
+ }
1081
+ function xn(e) {
1082
+ if (!e.result || typeof e.result != "object") return !1;
1083
+ const r = e.result;
1084
+ if (e.expectedResultOwner !== void 0 && r.resultOwner !== e.expectedResultOwner)
1085
+ return !1;
1086
+ if (!Ut({
1087
+ card: e.card,
1088
+ effectiveCardConfig: e.effectiveCardConfig
1089
+ }))
1090
+ return !0;
1091
+ if (!Array.isArray(r.records)) return !1;
1092
+ const t = Lt({
1093
+ card: e.card,
1094
+ effectiveCardConfig: e.effectiveCardConfig,
1095
+ records: r.records,
1096
+ columns: r.columns,
1097
+ columnKeyMap: r.columnKeyMap,
1098
+ preferences: de,
1099
+ calendar: { tz: "UTC" }
1100
+ });
1101
+ return t.kind === "inactive" || t.kind === "loaded_empty" || t.kind === "loaded_valid";
1102
+ }
1103
+ function Ie(e) {
1104
+ return !e || typeof e != "object" ? !1 : Array.isArray(e.cards);
1105
+ }
1106
+ function qt(e) {
1107
+ if (!e)
1108
+ return null;
1109
+ if (typeof e == "string")
1110
+ try {
1111
+ const r = JSON.parse(e);
1112
+ return Ie(r) ? r : null;
1113
+ } catch {
1114
+ return null;
1115
+ }
1116
+ return Ie(e) ? e : null;
1117
+ }
1118
+ function Pe(e) {
1119
+ var r;
1120
+ return (r = e == null ? void 0 : e.cards) != null && r.length ? e.activeCardId && e.cards.find((t) => t.id === e.activeCardId) || e.cards[0] : null;
1121
+ }
1122
+ function Sn(e) {
1123
+ var t;
1124
+ const r = (e == null ? void 0 : e.frameObject) ?? ((t = e == null ? void 0 : e.visual) == null ? void 0 : t.frameObject);
1125
+ return Pe(qt(r));
1126
+ }
1127
+ function fe(e) {
1128
+ if (!(e != null && e.expectedType)) return "table";
1129
+ const r = Array.isArray(e.expectedType) ? e.expectedType[0] : e.expectedType;
1130
+ return Ht(r) ? r : "table";
1131
+ }
1132
+ const Gt = [
1133
+ "bar",
1134
+ "horizontalBar",
1135
+ "line",
1136
+ "area",
1137
+ "stackedArea",
1138
+ "combo",
1139
+ "pie",
1140
+ "doughnut",
1141
+ "radar",
1142
+ "polarArea",
1143
+ "bubble",
1144
+ "scatter",
1145
+ "stackedBar",
1146
+ "stackedLine",
1147
+ "table",
1148
+ "pivotTable",
1149
+ "aggregateTable",
1150
+ "detailTable",
1151
+ "tableBuilder",
1152
+ "kpi",
1153
+ "pyramid",
1154
+ "tornado",
1155
+ "range",
1156
+ "text",
1157
+ "map",
1158
+ "funnel",
1159
+ "bullet",
1160
+ "heatmap",
1161
+ "treemap",
1162
+ "custom"
1163
+ ];
1164
+ function Ht(e) {
1165
+ return Gt.includes(e);
1166
+ }
1167
+ function G(e) {
1168
+ const r = e.position;
1169
+ if (typeof r == "number") return r;
1170
+ if (typeof r == "string") {
1171
+ const t = r.match(/\d+/);
1172
+ if (t) {
1173
+ const n = Number(t[0]);
1174
+ if (!Number.isNaN(n)) return n;
1175
+ }
1176
+ }
1177
+ return Number.POSITIVE_INFINITY;
1178
+ }
1179
+ function j(e) {
1180
+ if (typeof e == "number")
1181
+ return { kind: "number", start: e, end: e };
1182
+ if (typeof e == "string") {
1183
+ const r = e.match(/^(\d+)$/);
1184
+ if (r) {
1185
+ const o = Number(r[1]);
1186
+ return { kind: "number", start: o, end: o };
1187
+ }
1188
+ const t = e.match(/^(\d+)-(\d+)$/);
1189
+ if (t) {
1190
+ const o = Number(t[1]), a = Number(t[2]);
1191
+ return { kind: "range", start: o, end: a };
1192
+ }
1193
+ const n = e.match(/^(\d+)\+$/);
1194
+ if (n)
1195
+ return { kind: "dynamic", start: Number(n[1]), end: Number.POSITIVE_INFINITY };
1196
+ }
1197
+ return null;
1198
+ }
1199
+ function Me(e) {
1200
+ return !e || e.length === 0 ? void 0 : [...e].sort(
1201
+ (t, n) => G(t) - G(n)
1202
+ )[0];
1203
+ }
1204
+ function De(e, r) {
1205
+ if (!e || e.length === 0) return;
1206
+ const t = [], n = [], o = [];
1207
+ e.forEach((s) => {
1208
+ const u = j(s.position);
1209
+ u && (u.kind === "number" ? t.push(s) : u.kind === "range" ? n.push(s) : u.kind === "dynamic" && o.push(s));
1210
+ });
1211
+ const a = t.find((s) => {
1212
+ const u = j(s.position);
1213
+ return (u == null ? void 0 : u.kind) === "number" && u.start === r;
1214
+ });
1215
+ if (a) return a;
1216
+ const l = n.sort(
1217
+ (s, u) => G(s) - G(u)
1218
+ ).find((s) => {
1219
+ const u = j(s.position);
1220
+ return (u == null ? void 0 : u.kind) === "range" && r >= u.start && r <= u.end;
1221
+ });
1222
+ if (l) return l;
1223
+ const c = o.map((s) => ({
1224
+ slot: s,
1225
+ parsed: j(s.position)
1226
+ })).filter((s) => {
1227
+ var u;
1228
+ return ((u = s.parsed) == null ? void 0 : u.kind) === "dynamic";
1229
+ }).sort(
1230
+ (s, u) => {
1231
+ var p, d;
1232
+ return (((p = s.parsed) == null ? void 0 : p.start) ?? 0) - (((d = u.parsed) == null ? void 0 : d.start) ?? 0);
1233
+ }
1234
+ ).filter((s) => {
1235
+ var u;
1236
+ return r >= (((u = s.parsed) == null ? void 0 : u.start) ?? 0);
1237
+ }).sort(
1238
+ (s, u) => {
1239
+ var p, d;
1240
+ return (((p = u.parsed) == null ? void 0 : p.start) ?? 0) - (((d = s.parsed) == null ? void 0 : d.start) ?? 0);
1241
+ }
1242
+ )[0];
1243
+ return c == null ? void 0 : c.slot;
1244
+ }
1245
+ function Wt(e, r) {
1246
+ const t = De(e, r);
1247
+ if (t)
1248
+ return fe(t);
1249
+ }
1250
+ function Yt(e, r) {
1251
+ var n;
1252
+ const t = (n = e == null ? void 0 : e.customCardPreferences) == null ? void 0 : n.slotIndex;
1253
+ return typeof t == "number" ? t : r;
1254
+ }
1255
+ function we(e, r) {
1256
+ var t;
1257
+ if (!((t = e == null ? void 0 : e.customCardPreferences) != null && t.url))
1258
+ return !1;
1259
+ if (e.type === "custom" || e.customCardPreferences.visualType === "multiple" || e.customCardPreferences.dataInputCardIds || (e.customCardPreferences.minInputs || 0) > 1 || (e.customCardPreferences.maxInputs || 0) > 1)
1260
+ return !0;
1261
+ if (r && r.length > 1) {
1262
+ const n = r.filter(
1263
+ (o) => {
1264
+ var a;
1265
+ return typeof ((a = o.customCardPreferences) == null ? void 0 : a.slotIndex) == "number";
1266
+ }
1267
+ );
1268
+ if (n.length > 1 && n.some((o) => o.id !== e.id))
1269
+ return !0;
1270
+ }
1271
+ return !1;
1272
+ }
1273
+ function Zt(e) {
1274
+ const r = [];
1275
+ let t = -1;
1276
+ e.forEach((n, o) => {
1277
+ const a = Yt(n, o);
1278
+ a > t && (t = a), r[a] = n ?? null;
1279
+ });
1280
+ for (let n = 0; n <= t; n += 1)
1281
+ n in r || (r[n] = null);
1282
+ return r;
1283
+ }
1284
+ function _n(e) {
1285
+ return e.map((r, t) => !r.customCardPreferences || r.customCardPreferences.slotIndex === t ? r : {
1286
+ ...r,
1287
+ customCardPreferences: {
1288
+ ...r.customCardPreferences,
1289
+ slotIndex: t
1290
+ }
1291
+ });
1292
+ }
1293
+ function Fn(e) {
1294
+ const r = Me(e);
1295
+ if (r)
1296
+ return fe(r);
1297
+ }
1298
+ function Rn(e, r, t) {
1299
+ if (!e) return;
1300
+ const n = Wt(t, r);
1301
+ return e.type === "custom" && n ? n : e.type;
1302
+ }
1303
+ function An(e, r, t) {
1304
+ var v;
1305
+ const n = {
1306
+ dataSource: t.dataSource,
1307
+ connectionId: t.connectionId,
1308
+ lastSelectedDatabase: t.lastSelectedDatabase,
1309
+ lastSelectedSchema: t.lastSelectedSchema,
1310
+ lastSelectedTable: t.lastSelectedTable,
1311
+ lastSelectedDatamodelId: t.lastSelectedDatamodelId,
1312
+ datamodelId: t.datamodelId
1313
+ }, o = {
1314
+ type: "component",
1315
+ visualType: "multiple",
1316
+ url: r.url,
1317
+ componentName: r.name,
1318
+ icon: r.icon,
1319
+ pluginChartType: r.chartType,
1320
+ minInputs: r.minInputs,
1321
+ maxInputs: r.maxInputs
1322
+ }, a = r.minInputs || 1, l = e.map((h) => ({ slot: h, parsed: j(h.position) })).filter((h) => h.parsed !== null).reduce((h, I) => {
1323
+ const w = I.parsed.end;
1324
+ return Number.isFinite(w) ? Math.max(h, w) : h;
1325
+ }, -1), m = Math.max(a, l + 1), c = Me(e), s = c ? G(c) : 0;
1326
+ let u = !1;
1327
+ const p = [];
1328
+ for (let h = 0; h < m; h += 1) {
1329
+ const I = De(e, h), w = fe(I), g = !u && h === s, $ = h, E = {
1330
+ ...n,
1331
+ id: mt(),
1332
+ title: (g ? c == null ? void 0 : c.label : I == null ? void 0 : I.label) || `Tab ${h + 1}`,
1333
+ tabTitle: (g ? c == null ? void 0 : c.label : I == null ? void 0 : I.label) || `Tab ${h + 1}`,
1334
+ description: (g ? c == null ? void 0 : c.description : I == null ? void 0 : I.description) || "",
1335
+ type: w,
1336
+ sql: "",
1337
+ preferences: {
1338
+ onClickFilter: [{ columnIndex: 0, expression: "" }]
1339
+ },
1340
+ ...g && {
1341
+ customCardPreferences: {
1342
+ ...o,
1343
+ slotIndex: $
1344
+ }
1345
+ },
1346
+ ...!g && {
1347
+ customCardPreferences: {
1348
+ slotIndex: $
1349
+ }
1350
+ }
1351
+ };
1352
+ g && (u = !0), p.push(E);
1353
+ }
1354
+ if (!u && p.length > 0) {
1355
+ const h = ((v = p[0].customCardPreferences) == null ? void 0 : v.slotIndex) ?? 0;
1356
+ p[0] = {
1357
+ ...p[0],
1358
+ type: p[0].type,
1359
+ customCardPreferences: {
1360
+ ...o,
1361
+ slotIndex: h
1362
+ }
1363
+ };
1364
+ }
1365
+ const d = p.findIndex(
1366
+ (h) => {
1367
+ var I;
1368
+ return !!((I = h.customCardPreferences) != null && I.url);
1369
+ }
1370
+ );
1371
+ if (d > 0) {
1372
+ const [h] = p.splice(d, 1);
1373
+ p.unshift(h);
1374
+ }
1375
+ return p;
1376
+ }
1377
+ function Jt({
1378
+ frame: e,
1379
+ configCard: r,
1380
+ isMultiInputVisual: t
1381
+ }) {
1382
+ var o;
1383
+ if (!t || !r)
1384
+ return e.cards;
1385
+ const n = (o = r.customCardPreferences) == null ? void 0 : o.dataInputCardIds;
1386
+ return n ? Object.keys(n).sort((a, i) => Number(a) - Number(i)).map((a) => {
1387
+ var l;
1388
+ const i = (l = n[a]) == null ? void 0 : l.cardId;
1389
+ return e.cards.find((m) => m.id === i) || null;
1390
+ }) : e.cards;
1391
+ }
1392
+ function Qt(e, r) {
1393
+ return r && we(r, e.cards) ? r : e.cards.find((t) => we(t, e.cards)) || null;
1394
+ }
1395
+ function Xt(e, r) {
1396
+ var o, a;
1397
+ if (!e) return null;
1398
+ const t = r == null ? void 0 : r.visualType;
1399
+ if (t) return t;
1400
+ if (r != null && r.slots && r.slots.length > 0 || ((r == null ? void 0 : r.minInputs) || 0) > 1 || ((r == null ? void 0 : r.maxInputs) || 0) > 1 || ((r == null ? void 0 : r.dataInputs) || []).length > 1)
1401
+ return "multiple";
1402
+ const n = (o = e.customCardPreferences) == null ? void 0 : o.visualType;
1403
+ return n || ((a = e.customCardPreferences) != null && a.dataInputCardIds ? "multiple" : null);
1404
+ }
1405
+ function Bn(e) {
1406
+ return e.visualType === "multiple" || e.slots && e.slots.length > 0 || (e.minInputs || 0) > 1 || (e.maxInputs || 0) > 1 || (e.dataInputs || []).length > 1 ? "multiple" : "single";
1407
+ }
1408
+ function Pn(e) {
1409
+ return Array.isArray(e) ? { records: e } : e;
1410
+ }
1411
+ class W extends Error {
1412
+ constructor(t) {
1413
+ const n = t.cardId ? `card "${t.cardId}"` : t.sheetId ? `sheet "${t.sheetId}"` : `dashboard "${t.dashboardId}"`;
1414
+ super(
1415
+ `Unable to resolve ${n} while capturing report presentation. Refresh the authoring page and select the attachment again.`
1416
+ );
1417
+ S(this, "code", "temporal_snapshot_target_not_found");
1418
+ S(this, "selection");
1419
+ this.name = "TemporalSnapshotSelectionError", this.selection = t;
1420
+ }
1421
+ }
1422
+ function er(e, r) {
1423
+ var o;
1424
+ const t = [], n = /* @__PURE__ */ new Map();
1425
+ for (const a of r) {
1426
+ if (a.dashboardId !== e.id)
1427
+ throw new W(a);
1428
+ const i = (e.sheets || []).filter(
1429
+ (m) => !a.sheetId || a.sheetId === m.id
1430
+ );
1431
+ if (a.sheetId && i.length === 0)
1432
+ throw new W(a);
1433
+ let l = !a.cardId;
1434
+ for (const m of i) {
1435
+ const c = (((o = m.document) == null ? void 0 : o.sections) || []).flatMap(
1436
+ (p) => p.type === "table" || p.type === "chart" ? [p.card] : []
1437
+ ), s = (m.frames || []).flatMap(
1438
+ (p) => tr(p, a.cardId)
1439
+ );
1440
+ s.length > 0 && (l = !0);
1441
+ const u = [
1442
+ ...s,
1443
+ ...(m.cards || []).filter(
1444
+ (p) => !a.cardId || a.cardId === p.id
1445
+ ),
1446
+ ...c.filter(
1447
+ (p) => !a.cardId || a.cardId === p.id
1448
+ )
1449
+ ];
1450
+ for (const p of u) {
1451
+ l = !0;
1452
+ const d = n.get(a.attachmentIndex) ?? /* @__PURE__ */ new Set();
1453
+ d.has(p.id) || (d.add(p.id), n.set(a.attachmentIndex, d), t.push({
1454
+ card: p,
1455
+ ...a.attachmentIndex !== void 0 ? { attachmentIndex: a.attachmentIndex } : {}
1456
+ }));
1457
+ }
1458
+ }
1459
+ if (!l)
1460
+ throw new W(a);
1461
+ }
1462
+ return t;
1463
+ }
1464
+ function tr(e, r) {
1465
+ var i;
1466
+ const t = r ? (i = e.cards) == null ? void 0 : i.find((l) => l.id === r) : Pe(e);
1467
+ if (!t) return [];
1468
+ const n = Qt(e, t), o = (e.cards || []).filter(
1469
+ (l) => {
1470
+ var m;
1471
+ return typeof ((m = l.customCardPreferences) == null ? void 0 : m.slotIndex) == "number";
1472
+ }
1473
+ ).length > 1, a = n != null && (Xt(n) === "multiple" || o);
1474
+ return !n || !a ? [t] : Zt(
1475
+ Jt({
1476
+ frame: e,
1477
+ configCard: n,
1478
+ isMultiInputVisual: !0
1479
+ })
1480
+ ).filter((l) => l !== null);
1481
+ }
1482
+ function Mn(e) {
1483
+ return er(e.dashboard, e.selections).flatMap(
1484
+ ({ card: r, attachmentIndex: t }) => {
1485
+ var s, u, p, d;
1486
+ const n = ((s = e.resolveCardConfig) == null ? void 0 : s.call(e, r)) ?? r.config, o = Ft({
1487
+ card: r,
1488
+ cardConfig: n
1489
+ }), a = {
1490
+ dashboardId: e.dashboard.id,
1491
+ cardId: r.id,
1492
+ ...t !== void 0 ? { attachmentIndex: t } : {}
1493
+ }, i = o ? o.fields.map((v) => ({
1494
+ scope: a,
1495
+ target: {
1496
+ kind: "field",
1497
+ fieldId: v.id,
1498
+ role: v.role
1499
+ },
1500
+ format: Ot(
1501
+ v,
1502
+ {
1503
+ dateStyle: e.valueFormatPreferences.dateStyle,
1504
+ dateTime: { ...e.valueFormatPreferences.dateTime }
1505
+ },
1506
+ e.valueFormatPreferences.locale
1507
+ )
1508
+ })) : [], l = [], m = Q(r, n), c = H(
1509
+ r.python || ""
1510
+ );
1511
+ if (r.type === "detailTable" && m === "config") {
1512
+ const v = (n == null ? void 0 : n.detailColumns) || [], h = [
1513
+ ...((n == null ? void 0 : n.groupByColumns) || []).map((g) => ({
1514
+ field: g,
1515
+ role: "groupby"
1516
+ })),
1517
+ ...((n == null ? void 0 : n.metricColumns) || []).map((g) => ({
1518
+ field: g,
1519
+ role: "metric"
1520
+ })),
1521
+ ...((n == null ? void 0 : n.pivotByColumns) || []).map((g) => ({
1522
+ field: g,
1523
+ role: "pivotby"
1524
+ })),
1525
+ ...v.map((g) => ({
1526
+ field: g,
1527
+ role: "detail"
1528
+ }))
1529
+ ], I = /* @__PURE__ */ new Map(), w = new Set(
1530
+ h.map(
1531
+ ({ field: g, role: $ }) => Tt(g, $)
1532
+ )
1533
+ );
1534
+ for (const { field: g } of h) {
1535
+ const $ = g.label;
1536
+ $ && I.set($, (I.get($) || 0) + 1);
1537
+ }
1538
+ for (const g of v) {
1539
+ if (g.dateValueMode !== "canonical") continue;
1540
+ const $ = $t(g), E = g.label, F = kt({
1541
+ label: E,
1542
+ labelCount: E && I.get(E) || 0,
1543
+ rawKey: $,
1544
+ rawKeys: w
1545
+ });
1546
+ if (!F) throw new W(a);
1547
+ l.push({
1548
+ scope: a,
1549
+ target: { kind: "column", columnKey: F },
1550
+ format: q({
1551
+ format: Be(g),
1552
+ preferences: e.valueFormatPreferences,
1553
+ calendar: e.calendar
1554
+ })
1555
+ });
1556
+ }
1557
+ } else if (m === "freeform" && ((u = r.sql) != null && u.trim()) && !c.trim())
1558
+ for (const [v, h] of Object.entries(
1559
+ ((d = (p = r.preferences) == null ? void 0 : p.tablePrefs) == null ? void 0 : d.columnSettingsMap) || {}
1560
+ )) {
1561
+ if (h.type !== "date") continue;
1562
+ const I = me(
1563
+ h.dateFormat
1564
+ );
1565
+ I && l.push({
1566
+ scope: a,
1567
+ target: { kind: "column", columnKey: v },
1568
+ format: q({
1569
+ format: I,
1570
+ preferences: e.valueFormatPreferences,
1571
+ calendar: e.calendar
1572
+ })
1573
+ });
1574
+ }
1575
+ return [...i, ...l];
1576
+ }
1577
+ );
1578
+ }
1579
+ function rr(e) {
1580
+ return !!e && typeof e == "object" && !Array.isArray(e);
1581
+ }
1582
+ function A(e, r, t) {
1583
+ return rr(e) ? e : (t.push({ field: r, message: "Expected an object." }), {});
1584
+ }
1585
+ function B(e, r, t, n) {
1586
+ const o = new Set(t);
1587
+ Object.keys(e).forEach((a) => {
1588
+ o.has(a) || n.push({
1589
+ field: `${r}.${a}`,
1590
+ message: "Unexpected property."
1591
+ });
1592
+ });
1593
+ }
1594
+ function M(e, r, t, n, o = {}) {
1595
+ if (e == null)
1596
+ return;
1597
+ if (typeof e != "string") {
1598
+ n.push({ field: r, message: "Expected a string." });
1599
+ return;
1600
+ }
1601
+ const a = o.trim === !1 ? e : e.trim();
1602
+ if (!o.allowEmpty && a.length === 0) {
1603
+ n.push({ field: r, message: "Expected a non-empty string." });
1604
+ return;
1605
+ }
1606
+ if (a.length > t) {
1607
+ n.push({
1608
+ field: r,
1609
+ message: `Expected ${t} characters or fewer.`
1610
+ });
1611
+ return;
1612
+ }
1613
+ return a;
1614
+ }
1615
+ function pe(e, r, t) {
1616
+ const n = M(e, r, 2e3, t);
1617
+ if (n)
1618
+ try {
1619
+ return new URL(n), n;
1620
+ } catch {
1621
+ t.push({ field: r, message: "Expected an absolute URL." });
1622
+ return;
1623
+ }
1624
+ }
1625
+ function Ce(e, r, t) {
1626
+ const n = A(e, r, t);
1627
+ B(n, r, ["tokens", "components"], t);
1628
+ const o = {};
1629
+ if (n.tokens !== void 0) {
1630
+ const a = A(n.tokens, `${r}.tokens`, t);
1631
+ B(
1632
+ a,
1633
+ `${r}.tokens`,
1634
+ ["color", "typography"],
1635
+ t
1636
+ );
1637
+ const i = {};
1638
+ if (a.color !== void 0) {
1639
+ const l = A(
1640
+ a.color,
1641
+ `${r}.tokens.color`,
1642
+ t
1643
+ ), m = [
1644
+ "background",
1645
+ "foreground",
1646
+ "muted",
1647
+ "mutedForeground",
1648
+ "border",
1649
+ "primary",
1650
+ "primaryForeground",
1651
+ "positive",
1652
+ "negative",
1653
+ "warning",
1654
+ "info"
1655
+ ];
1656
+ B(l, `${r}.tokens.color`, m, t);
1657
+ const c = {};
1658
+ m.forEach((s) => {
1659
+ const u = M(
1660
+ l[s],
1661
+ `${r}.tokens.color.${s}`,
1662
+ 120,
1663
+ t
1664
+ );
1665
+ u !== void 0 && (c[s] = u);
1666
+ }), i.color = c;
1667
+ }
1668
+ if (a.typography !== void 0) {
1669
+ const l = A(
1670
+ a.typography,
1671
+ `${r}.tokens.typography`,
1672
+ t
1673
+ );
1674
+ B(
1675
+ l,
1676
+ `${r}.tokens.typography`,
1677
+ ["fontFamily", "monoFontFamily"],
1678
+ t
1679
+ );
1680
+ const m = M(
1681
+ l.fontFamily,
1682
+ `${r}.tokens.typography.fontFamily`,
1683
+ 500,
1684
+ t,
1685
+ { allowEmpty: !0 }
1686
+ ), c = M(
1687
+ l.monoFontFamily,
1688
+ `${r}.tokens.typography.monoFontFamily`,
1689
+ 500,
1690
+ t,
1691
+ { allowEmpty: !0 }
1692
+ );
1693
+ i.typography = {
1694
+ ...m !== void 0 ? { fontFamily: m } : {},
1695
+ ...c !== void 0 ? { monoFontFamily: c } : {}
1696
+ };
1697
+ }
1698
+ o.tokens = i;
1699
+ }
1700
+ if (n.components !== void 0) {
1701
+ const a = A(
1702
+ n.components,
1703
+ `${r}.components`,
1704
+ t
1705
+ );
1706
+ if (B(a, `${r}.components`, ["chart"], t), a.chart !== void 0) {
1707
+ const i = A(
1708
+ a.chart,
1709
+ `${r}.components.chart`,
1710
+ t
1711
+ );
1712
+ B(i, `${r}.components.chart`, ["palette"], t);
1713
+ let l;
1714
+ i.palette !== void 0 && (Array.isArray(i.palette) ? i.palette.length > 20 ? t.push({
1715
+ field: `${r}.components.chart.palette`,
1716
+ message: "Expected 20 colors or fewer."
1717
+ }) : l = i.palette.map(
1718
+ (m, c) => M(
1719
+ m,
1720
+ `${r}.components.chart.palette.${c}`,
1721
+ 120,
1722
+ t
1723
+ )
1724
+ ).filter((m) => m !== void 0) : t.push({
1725
+ field: `${r}.components.chart.palette`,
1726
+ message: "Expected an array."
1727
+ })), o.components = {
1728
+ chart: l ? { palette: l } : {}
1729
+ };
1730
+ }
1731
+ }
1732
+ return o;
1733
+ }
1734
+ function nr(e, r) {
1735
+ const t = "presentation.appearance", n = A(e, t, r);
1736
+ B(n, t, ["version", "schemes"], r);
1737
+ const o = {};
1738
+ if (n.version !== void 0 && (typeof n.version != "number" || !Number.isFinite(n.version) ? r.push({ field: `${t}.version`, message: "Expected a number." }) : o.version = n.version), n.schemes !== void 0) {
1739
+ const a = A(n.schemes, `${t}.schemes`, r);
1740
+ B(a, `${t}.schemes`, ["light", "dark"], r), o.schemes = {
1741
+ ...a.light !== void 0 ? {
1742
+ light: Ce(
1743
+ a.light,
1744
+ `${t}.schemes.light`,
1745
+ r
1746
+ )
1747
+ } : {},
1748
+ ...a.dark !== void 0 ? {
1749
+ dark: Ce(
1750
+ a.dark,
1751
+ `${t}.schemes.dark`,
1752
+ r
1753
+ )
1754
+ } : {}
1755
+ };
1756
+ }
1757
+ return o;
1758
+ }
1759
+ function or(e, r) {
1760
+ const t = "presentation.brandOverrides", n = A(e, t, r);
1761
+ B(n, t, ["brandName", "logoUrl", "link"], r);
1762
+ const o = M(
1763
+ n.brandName,
1764
+ `${t}.brandName`,
1765
+ 200,
1766
+ r
1767
+ ), a = pe(n.logoUrl, `${t}.logoUrl`, r), i = M(n.link, `${t}.link`, 120, r);
1768
+ return {
1769
+ ...o !== void 0 ? { brandName: o } : {},
1770
+ ...a !== void 0 ? { logoUrl: a } : {},
1771
+ ...i !== void 0 ? { link: i } : {}
1772
+ };
1773
+ }
1774
+ function ar(e, r) {
1775
+ const t = "presentation.fragments", n = A(e, t, r), o = [
1776
+ "preHeaderText",
1777
+ "headerBannerHtml",
1778
+ "signatureHtml",
1779
+ "footerHtml",
1780
+ "disclaimerHtml",
1781
+ "unsubscribeUrl"
1782
+ ];
1783
+ B(n, t, o, r);
1784
+ const a = {};
1785
+ return o.forEach((i) => {
1786
+ const l = i === "unsubscribeUrl" ? pe(n[i], `${t}.${i}`, r) : M(
1787
+ n[i],
1788
+ `${t}.${i}`,
1789
+ i === "preHeaderText" ? 200 : 5e3,
1790
+ r,
1791
+ { trim: i === "preHeaderText" }
1792
+ );
1793
+ l !== void 0 && (a[i] = l);
1794
+ }), a;
1795
+ }
1796
+ function ir(e) {
1797
+ const r = [], t = {};
1798
+ if (e.appearance !== void 0 && (t.appearance = nr(e.appearance, r)), e.brandOverrides !== void 0 && (t.brandOverrides = or(e.brandOverrides, r)), e.fragments !== void 0 && (t.fragments = ar(e.fragments, r)), e.viewUrl !== void 0) {
1799
+ const n = pe(e.viewUrl, "presentation.viewUrl", r);
1800
+ n !== void 0 && (t.viewUrl = n);
1801
+ }
1802
+ return { value: t, issues: r };
1803
+ }
1804
+ const Oe = [
1805
+ "SUN",
1806
+ "MON",
1807
+ "TUE",
1808
+ "WED",
1809
+ "THU",
1810
+ "FRI",
1811
+ "SAT"
1812
+ ], cr = new Map(
1813
+ Oe.map((e, r) => [e, r])
1814
+ ), Dn = {
1815
+ cadence: "weekly",
1816
+ hour: 9,
1817
+ minute: 0,
1818
+ weekdays: [1]
1819
+ };
1820
+ function On(e) {
1821
+ if (typeof e != "string" || e.length === 0 || e !== e.trim() || /^(?:(?:UTC|GMT)[+-]|[+-]\d{2}:\d{2}$)/.test(e))
1822
+ return !1;
1823
+ try {
1824
+ return new Intl.DateTimeFormat("en-US", { timeZone: e }).format(), !0;
1825
+ } catch {
1826
+ return !1;
1827
+ }
1828
+ }
1829
+ function lr(e) {
1830
+ return Number.isInteger(e.minute) && e.minute >= 0 && e.minute <= 59 && Number.isInteger(e.hour) && e.hour >= 0 && e.hour <= 23;
1831
+ }
1832
+ function Ke(e) {
1833
+ if (e.length === 0) return null;
1834
+ const r = [...e].sort((t, n) => t - n);
1835
+ return r.some(
1836
+ (t, n) => !Number.isInteger(t) || t < 0 || t > 6 || n > 0 && t === r[n - 1]
1837
+ ) ? null : r;
1838
+ }
1839
+ function Kn(e) {
1840
+ if (!lr(e))
1841
+ throw new Error("Choose a valid schedule time.");
1842
+ const r = `${e.minute} ${e.hour}`;
1843
+ switch (e.cadence) {
1844
+ case "daily":
1845
+ return `${r} * * *`;
1846
+ case "weekly": {
1847
+ const t = Ke(e.weekdays);
1848
+ if (!t) throw new Error("Choose at least one weekday.");
1849
+ return `${r} * * ${t.map((n) => Oe[n]).join(",")}`;
1850
+ }
1851
+ case "twice_monthly":
1852
+ return `${r} 1,15 * *`;
1853
+ case "monthly":
1854
+ return `${r} 1 * *`;
1855
+ }
1856
+ }
1857
+ function dr(e) {
1858
+ if (typeof e != "string" || e.length === 0)
1859
+ return { ok: !1, issue: "Choose a supported schedule." };
1860
+ if (e !== e.trim() || e.includes(" "))
1861
+ return { ok: !1, issue: "Choose a supported schedule." };
1862
+ const r = e.split(" ");
1863
+ if (r.length !== 5)
1864
+ return { ok: !1, issue: "Choose a supported schedule." };
1865
+ const [t, n, o, a, i] = r;
1866
+ if (!/^(0|[1-9]\d?)$/.test(t) || !/^(0|[1-9]\d?)$/.test(n))
1867
+ return { ok: !1, issue: "Choose a supported schedule." };
1868
+ const l = Number(t), m = Number(n);
1869
+ if (l > 59 || m > 23 || a !== "*")
1870
+ return { ok: !1, issue: "Choose a supported schedule." };
1871
+ if (o === "*" && i === "*")
1872
+ return {
1873
+ ok: !0,
1874
+ value: { cadence: "daily", hour: m, minute: l, weekdays: [] }
1875
+ };
1876
+ if (o === "*" && i !== "*") {
1877
+ const s = i.split(",").map((d) => cr.get(d));
1878
+ if (s.some((d) => d === void 0))
1879
+ return { ok: !1, issue: "Choose a supported schedule." };
1880
+ const u = s, p = Ke(u);
1881
+ return !p || p.some((d, v) => d !== u[v]) ? { ok: !1, issue: "Choose a supported schedule." } : {
1882
+ ok: !0,
1883
+ value: { cadence: "weekly", hour: m, minute: l, weekdays: p }
1884
+ };
1885
+ }
1886
+ return o === "1,15" && i === "*" ? {
1887
+ ok: !0,
1888
+ value: { cadence: "twice_monthly", hour: m, minute: l, weekdays: [] }
1889
+ } : o === "1" && i === "*" ? {
1890
+ ok: !0,
1891
+ value: { cadence: "monthly", hour: m, minute: l, weekdays: [] }
1892
+ } : { ok: !1, issue: "Choose a supported schedule." };
1893
+ }
1894
+ function sr(e, r, t) {
1895
+ return new Intl.DateTimeFormat(t, {
1896
+ hour: "numeric",
1897
+ minute: "2-digit",
1898
+ timeZone: "UTC"
1899
+ }).format(new Date(Date.UTC(2020, 0, 1, e, r)));
1900
+ }
1901
+ function mr(e, r) {
1902
+ var t;
1903
+ if (e === "UTC") return "UTC";
1904
+ try {
1905
+ return ((t = new Intl.DateTimeFormat(r, {
1906
+ timeZone: e,
1907
+ timeZoneName: "longGeneric"
1908
+ }).formatToParts(new Date(Date.UTC(2020, 0, 1))).find((o) => o.type === "timeZoneName")) == null ? void 0 : t.value) ?? e;
1909
+ } catch {
1910
+ return null;
1911
+ }
1912
+ }
1913
+ function Nn(e, r, t = "en-US") {
1914
+ const n = dr(e);
1915
+ if (!n.ok) return null;
1916
+ try {
1917
+ const o = sr(n.value.hour, n.value.minute, t), a = mr(r, t);
1918
+ if (!a) return null;
1919
+ switch (n.value.cadence) {
1920
+ case "daily":
1921
+ return `Daily at ${o} ${a}`;
1922
+ case "weekly": {
1923
+ const i = new Intl.DateTimeFormat(t, {
1924
+ weekday: "long",
1925
+ timeZone: "UTC"
1926
+ });
1927
+ return `${n.value.weekdays.map(
1928
+ (m) => i.format(new Date(Date.UTC(2023, 0, 1 + m)))
1929
+ ).join(" and ")} at ${o} ${a}`;
1930
+ }
1931
+ case "twice_monthly":
1932
+ return `On the 1st and 15th at ${o} ${a}`;
1933
+ case "monthly":
1934
+ return `Monthly on the 1st at ${o} ${a}`;
1935
+ }
1936
+ } catch {
1937
+ return null;
1938
+ }
1939
+ }
1940
+ const ur = /* @__PURE__ */ new Set([
1941
+ "table",
1942
+ "aggregateTable",
1943
+ "pivotTable",
1944
+ "detailTable"
1945
+ ]), fr = /* @__PURE__ */ new Set([
1946
+ "bar",
1947
+ "horizontalBar",
1948
+ "line",
1949
+ "area",
1950
+ "stackedArea",
1951
+ "combo",
1952
+ "pie",
1953
+ "doughnut",
1954
+ "radar",
1955
+ "polarArea",
1956
+ "bubble",
1957
+ "scatter",
1958
+ "stackedBar",
1959
+ "stackedLine",
1960
+ "table",
1961
+ "pivotTable",
1962
+ "aggregateTable",
1963
+ "matrixTable",
1964
+ "detailTable",
1965
+ "kpi",
1966
+ "pyramid",
1967
+ "tornado",
1968
+ "range",
1969
+ "map",
1970
+ "funnel",
1971
+ "bullet",
1972
+ "heatmap",
1973
+ "treemap",
1974
+ "custom"
1975
+ ]);
1976
+ function zn(e) {
1977
+ var n, o, a;
1978
+ const r = fr.has(e.type) && (e.type !== "custom" || !!((n = e.customCardPreferences) != null && n.url));
1979
+ return e.type === "text" || !r || ut(e) ? { formats: [], defaultFormat: null } : {
1980
+ formats: pr({
1981
+ cardType: e.type,
1982
+ allowDownload: (o = e.preferences) == null ? void 0 : o.allowDownload
1983
+ }),
1984
+ defaultFormat: yr({
1985
+ cardType: e.type,
1986
+ allowDownload: (a = e.preferences) == null ? void 0 : a.allowDownload
1987
+ })
1988
+ };
1989
+ }
1990
+ function pr(e) {
1991
+ return e.allowDownload === !1 ? ["pdf"] : ["pdf", "csv"];
1992
+ }
1993
+ function yr(e) {
1994
+ return ur.has(e.cardType) && e.allowDownload !== !1 ? "csv" : "pdf";
1995
+ }
1996
+ function Vn(e) {
1997
+ return e != null && e.role ? e.type === "tenant" ? e.role === "POWER_USER" : ["AUTHOR", "ADMIN", "SUPER_ADMIN"].includes(e.role) : !1;
1998
+ }
1999
+ function Ln(e) {
2000
+ return e.canCreate ? [
2001
+ ...e.scheduledReportAvailable ? ["scheduled_report"] : [],
2002
+ ...e.analyticalBriefingsEnabled ? ["analytical_briefing"] : []
2003
+ ] : [];
2004
+ }
2005
+ function hr(e) {
2006
+ const r = (e == null ? void 0 : e.channels) ?? [];
2007
+ return r.length === 1 && r[0] === "EMAIL";
2008
+ }
2009
+ function gr(e) {
2010
+ return e.body.type === "generated_analysis" ? "Analytical briefing" : e.body.type === "custom_message" && e.attachments.length > 0 && hr(e.deliveryConfig) ? e.scheduleExpr ? "Scheduled report" : "On-demand report" : "Plain briefing";
2011
+ }
2012
+ function Un(e) {
2013
+ const r = gr(e), t = r === "Scheduled report" || r === "On-demand report" ? "report" : "briefing";
2014
+ return {
2015
+ typeLabel: r,
2016
+ noun: t,
2017
+ pluralNoun: t === "report" ? "reports" : "briefings"
2018
+ };
2019
+ }
2020
+ const ce = "BRIEFING", vr = ["markdown", "html"], le = ["markdown"], te = 20, y = {
2021
+ name: 500,
2022
+ description: 2e3,
2023
+ instruction: 5e4,
2024
+ customMessage: 5e4,
2025
+ contentTitle: 500,
2026
+ contentSummary: 2e4,
2027
+ contentText: 5e3,
2028
+ contentSql: 5e4,
2029
+ contentItem: 2e3,
2030
+ contentCell: 500,
2031
+ attachmentTitle: 500,
2032
+ presentationAudience: 1e3,
2033
+ presentationTone: 500,
2034
+ presentationFormat: 2e3,
2035
+ id: 500
2036
+ }, _ = {
2037
+ maxBlocks: 50,
2038
+ maxTableRows: 100,
2039
+ maxTableColumns: 20,
2040
+ maxTableCellCharacters: y.contentCell,
2041
+ maxParagraphCharacters: y.contentText,
2042
+ maxFindingCharacters: y.contentText,
2043
+ maxListItems: 100,
2044
+ // A kpi_grid is rendered as a 2-up tile arrangement in emails. Cap at 8 so
2045
+ // the visual stays at most 4 rows (4 columns wide on desktop would force
2046
+ // tiny tiles in narrow client panels; 2-up was the chosen layout).
2047
+ maxKpiTiles: 8
2048
+ };
2049
+ function br(e) {
2050
+ if (e === null || typeof e != "object" || Array.isArray(e))
2051
+ return !1;
2052
+ const r = e;
2053
+ if (typeof r.value != "number" || !Number.isFinite(r.value))
2054
+ return !1;
2055
+ const t = r.target;
2056
+ if (t === null || typeof t != "object" || Array.isArray(t))
2057
+ return !1;
2058
+ const n = t;
2059
+ return (n.kind === "metric" && typeof n.metricId == "string" && !!n.metricId.trim() || n.kind === "column" && typeof n.columnKey == "string" && !!n.columnKey.trim() || n.kind === "matrix_measure" && typeof n.measureId == "string" && !!n.measureId.trim()) && Te(r.format).ok;
2060
+ }
2061
+ function Ir(e) {
2062
+ return e == null ? "" : br(e) ? ct(e.value, e.format) : String(e);
2063
+ }
2064
+ function jn(e) {
2065
+ return [e.delta, e.percentChange].filter(
2066
+ (r) => r != null
2067
+ ).map(Ir).filter(Boolean).join(" / ");
2068
+ }
2069
+ const Ne = new Set(vr), wr = /* @__PURE__ */ new Set([
2070
+ "EMAIL",
2071
+ "WEBHOOK",
2072
+ "SLACK",
2073
+ "IN_APP",
2074
+ "TELEGRAM"
2075
+ ]), re = {
2076
+ maxToolCalls: { min: 1, max: 100 },
2077
+ maxPlanningIterations: { min: 1, max: 10 },
2078
+ maxRows: { min: 1, max: 1e5 },
2079
+ timeoutMs: { min: 1e3, max: 30 * 6e4 }
2080
+ }, Cr = /* @__PURE__ */ new Set([
2081
+ "letter",
2082
+ "legal",
2083
+ "a4",
2084
+ "a3",
2085
+ "tabloid"
2086
+ ]), Tr = /* @__PURE__ */ new Set([
2087
+ "portrait",
2088
+ "landscape"
2089
+ ]), $r = /* @__PURE__ */ new Set([",", ";", " "]), kr = /* @__PURE__ */ new Set([
2090
+ "current",
2091
+ "all"
2092
+ ]), Er = /* @__PURE__ */ new Set([
2093
+ "concise",
2094
+ "balanced",
2095
+ "detailed"
2096
+ ]), xr = /* @__PURE__ */ new Set([
2097
+ "info",
2098
+ "positive",
2099
+ "warning",
2100
+ "critical"
2101
+ ]), Sr = /* @__PURE__ */ new Set([
2102
+ "text",
2103
+ "number",
2104
+ "currency",
2105
+ "percent",
2106
+ "date",
2107
+ "boolean"
2108
+ ]), _r = /* @__PURE__ */ new Set([
2109
+ "left",
2110
+ "center",
2111
+ "right"
2112
+ ]), Fr = [
2113
+ "pageSize",
2114
+ "orientation",
2115
+ "includeFilters",
2116
+ "includeTimestamp",
2117
+ "delimiter",
2118
+ "includeHeaders",
2119
+ "useFormattedValues",
2120
+ "sheetSelection",
2121
+ "currentSheetId",
2122
+ "currentSheetName",
2123
+ "filterValues",
2124
+ "inlineFilterValues",
2125
+ "sheetFilterValues",
2126
+ "filterLine",
2127
+ "controlValues",
2128
+ "controlDefinitions",
2129
+ "cardControlDefinitions",
2130
+ "controlBindings",
2131
+ "tablePreferences",
2132
+ "dashboardInputExecutionSnapshot",
2133
+ "selectedSheetId",
2134
+ "cardType",
2135
+ "allowDownload",
2136
+ "theme"
2137
+ ];
2138
+ class X extends Error {
2139
+ constructor(t) {
2140
+ super(t.map((n) => `${n.field}: ${n.message}`).join("; "));
2141
+ S(this, "issues");
2142
+ this.name = "BriefingContractError", this.issues = t;
2143
+ }
2144
+ }
2145
+ function ze(e) {
2146
+ return typeof e == "object" && e !== null && !Array.isArray(e);
2147
+ }
2148
+ function f(e, r, t) {
2149
+ e.push({ field: r, message: t });
2150
+ }
2151
+ function k(e, r, t) {
2152
+ return ze(e) ? e : (f(t, r, "Expected an object."), {});
2153
+ }
2154
+ function b(e, r, t, n) {
2155
+ const o = new Set(t);
2156
+ Object.keys(e).forEach((a) => {
2157
+ o.has(a) || f(
2158
+ n,
2159
+ r ? `${r}.${a}` : a,
2160
+ `Unexpected field "${a}".`
2161
+ );
2162
+ });
2163
+ }
2164
+ function C(e, r, t, n) {
2165
+ if (typeof e != "string")
2166
+ return f(n, r, "Expected a string."), "";
2167
+ const o = e.trim();
2168
+ return o ? (o.length > t && f(n, r, `Must be ${t} characters or fewer.`), o) : (f(n, r, "Required value cannot be empty."), "");
2169
+ }
2170
+ function T(e, r, t, n) {
2171
+ if (e == null)
2172
+ return;
2173
+ if (typeof e != "string") {
2174
+ f(n, r, "Expected a string.");
2175
+ return;
2176
+ }
2177
+ const o = e.trim();
2178
+ if (o)
2179
+ return o.length > t && f(n, r, `Must be ${t} characters or fewer.`), o;
2180
+ }
2181
+ function Rr(e, r, t, n) {
2182
+ if (typeof e != "string")
2183
+ return f(n, r, "Expected a string."), "";
2184
+ const o = e.trim();
2185
+ return o.length > t && f(n, r, `Must be ${t} characters or fewer.`), o;
2186
+ }
2187
+ function Ar(e, r, t) {
2188
+ if (e != null) {
2189
+ if (!Number.isInteger(e) || Number(e) < 0) {
2190
+ f(t, r, "Expected a non-negative integer.");
2191
+ return;
2192
+ }
2193
+ return Number(e);
2194
+ }
2195
+ }
2196
+ function R(e, r, t, n = {}) {
2197
+ if (e == null)
2198
+ return n.required ? (f(t, r, "Expected at least one evidence id."), []) : void 0;
2199
+ if (!Array.isArray(e))
2200
+ return f(t, r, "Expected an array."), n.required ? [] : void 0;
2201
+ const o = [];
2202
+ return e.forEach((a, i) => {
2203
+ const l = C(
2204
+ a,
2205
+ `${r}.${i}`,
2206
+ y.id,
2207
+ t
2208
+ );
2209
+ l && !o.includes(l) && o.push(l);
2210
+ }), n.required && o.length === 0 && f(t, r, "Expected at least one evidence id."), o.length > 0 || n.required ? o : void 0;
2211
+ }
2212
+ function N(e, r, t, n) {
2213
+ return e == null ? r : typeof e != "boolean" ? (f(n, t, "Expected a boolean."), r) : e;
2214
+ }
2215
+ function Br(e, r) {
2216
+ return e == null ? "ACTIVE" : e === "ACTIVE" || e === "PAUSED" || e === "DISABLED" ? e : (f(r, "status", "Expected ACTIVE, PAUSED, or DISABLED."), "ACTIVE");
2217
+ }
2218
+ function Pr(e) {
2219
+ return e.includes("@") && e.includes(".") && !e.includes(" ");
2220
+ }
2221
+ function Ve(e, r) {
2222
+ if (e == null)
2223
+ return { type: "project" };
2224
+ const t = k(e, "source", r), n = t.type;
2225
+ return n === "project" ? (b(t, "source", ["type"], r), { type: "project" }) : n === "dashboard" ? (b(t, "source", ["type", "dashboardId"], r), {
2226
+ type: "dashboard",
2227
+ dashboardId: C(
2228
+ t.dashboardId,
2229
+ "source.dashboardId",
2230
+ y.id,
2231
+ r
2232
+ )
2233
+ }) : (f(r, "source.type", "Expected project or dashboard."), { type: "project" });
2234
+ }
2235
+ function Le(e, r) {
2236
+ const t = k(e, "body", r), n = t.type;
2237
+ return n === "generated_analysis" ? (b(t, "body", ["type", "instruction"], r), {
2238
+ type: "generated_analysis",
2239
+ instruction: C(
2240
+ t.instruction,
2241
+ "body.instruction",
2242
+ y.instruction,
2243
+ r
2244
+ )
2245
+ }) : n === "custom_message" ? (b(t, "body", ["type", "message"], r), {
2246
+ type: "custom_message",
2247
+ message: Rr(
2248
+ t.message,
2249
+ "body.message",
2250
+ y.customMessage,
2251
+ r
2252
+ )
2253
+ }) : n === "none" ? (b(t, "body", ["type"], r), { type: "none" }) : (f(
2254
+ r,
2255
+ "body.type",
2256
+ "Expected generated_analysis, custom_message, or none."
2257
+ ), { type: "none" });
2258
+ }
2259
+ function Mr(e, r) {
2260
+ if (e == null)
2261
+ return [...le];
2262
+ if (!Array.isArray(e))
2263
+ return f(r, "presentation.artifactFormats", "Expected an array."), [...le];
2264
+ if (e.length === 0)
2265
+ return f(
2266
+ r,
2267
+ "presentation.artifactFormats",
2268
+ "Choose at least one artifact format."
2269
+ ), [];
2270
+ const t = [];
2271
+ return e.forEach((n, o) => {
2272
+ if (typeof n != "string" || !Ne.has(n)) {
2273
+ f(
2274
+ r,
2275
+ `presentation.artifactFormats.${o}`,
2276
+ "Expected markdown or html."
2277
+ );
2278
+ return;
2279
+ }
2280
+ t.includes(n) || t.push(n);
2281
+ }), t;
2282
+ }
2283
+ function Ue(e, r) {
2284
+ if (e == null)
2285
+ return {
2286
+ artifactFormats: [...le],
2287
+ includeEvidence: !0,
2288
+ includeSql: !0
2289
+ };
2290
+ const t = k(e, "presentation", r);
2291
+ b(
2292
+ t,
2293
+ "presentation",
2294
+ [
2295
+ "artifactFormats",
2296
+ "includeEvidence",
2297
+ "includeSql",
2298
+ "audience",
2299
+ "tone",
2300
+ "format",
2301
+ "appearance",
2302
+ "brandOverrides",
2303
+ "fragments",
2304
+ "viewUrl"
2305
+ ],
2306
+ r
2307
+ );
2308
+ const n = {
2309
+ artifactFormats: Mr(t.artifactFormats, r),
2310
+ includeEvidence: N(
2311
+ t.includeEvidence,
2312
+ !0,
2313
+ "presentation.includeEvidence",
2314
+ r
2315
+ ),
2316
+ includeSql: N(
2317
+ t.includeSql,
2318
+ !0,
2319
+ "presentation.includeSql",
2320
+ r
2321
+ )
2322
+ }, o = T(
2323
+ t.audience,
2324
+ "presentation.audience",
2325
+ y.presentationAudience,
2326
+ r
2327
+ ), a = T(
2328
+ t.tone,
2329
+ "presentation.tone",
2330
+ y.presentationTone,
2331
+ r
2332
+ ), i = T(
2333
+ t.format,
2334
+ "presentation.format",
2335
+ y.presentationFormat,
2336
+ r
2337
+ );
2338
+ o && (n.audience = o), a && (n.tone = a), i && (n.format = i);
2339
+ const l = ir(t);
2340
+ return l.issues.forEach((m) => f(r, m.field, m.message)), Object.assign(n, l.value), n;
2341
+ }
2342
+ function Dr(e, r, t) {
2343
+ return Array.isArray(e) ? (e.length === 0 && f(t, r, "Expected at least one item."), e.length > _.maxListItems && f(
2344
+ t,
2345
+ r,
2346
+ `Must have ${_.maxListItems} items or fewer.`
2347
+ ), e.slice(0, _.maxListItems).map(
2348
+ (n, o) => C(
2349
+ n,
2350
+ `${r}.${o}`,
2351
+ y.contentItem,
2352
+ t
2353
+ )
2354
+ ).filter(Boolean)) : (f(t, r, "Expected an array."), []);
2355
+ }
2356
+ function Or(e, r, t) {
2357
+ const n = k(e, r, t);
2358
+ if (n.kind === "metric")
2359
+ return b(n, r, ["kind", "metricId"], t), {
2360
+ kind: "metric",
2361
+ metricId: C(
2362
+ n.metricId,
2363
+ `${r}.metricId`,
2364
+ y.id,
2365
+ t
2366
+ )
2367
+ };
2368
+ if (n.kind === "column")
2369
+ return b(n, r, ["kind", "columnKey"], t), {
2370
+ kind: "column",
2371
+ columnKey: C(
2372
+ n.columnKey,
2373
+ `${r}.columnKey`,
2374
+ y.id,
2375
+ t
2376
+ )
2377
+ };
2378
+ if (n.kind === "matrix_measure")
2379
+ return b(n, r, ["kind", "measureId"], t), {
2380
+ kind: "matrix_measure",
2381
+ measureId: C(
2382
+ n.measureId,
2383
+ `${r}.measureId`,
2384
+ y.id,
2385
+ t
2386
+ )
2387
+ };
2388
+ f(
2389
+ t,
2390
+ `${r}.kind`,
2391
+ "Expected metric, column, or matrix_measure."
2392
+ );
2393
+ }
2394
+ function je(e, r, t) {
2395
+ if (e === null || typeof e != "object" || Array.isArray(e))
2396
+ return;
2397
+ const n = k(e, r, t);
2398
+ if (!Object.prototype.hasOwnProperty.call(n, "target") && !Object.prototype.hasOwnProperty.call(n, "format"))
2399
+ return;
2400
+ b(n, r, ["value", "target", "format"], t), (typeof n.value != "number" || !Number.isFinite(n.value)) && f(t, `${r}.value`, "Expected a finite number.");
2401
+ const o = Or(
2402
+ n.target,
2403
+ `${r}.target`,
2404
+ t
2405
+ ), a = Te(n.format);
2406
+ if (a.ok || a.issues.forEach(
2407
+ (i) => f(
2408
+ t,
2409
+ i.path === "$" ? `${r}.format` : `${r}.format.${i.path}`,
2410
+ i.message
2411
+ )
2412
+ ), !(typeof n.value != "number" || !Number.isFinite(n.value) || !o || !a.ok))
2413
+ return { value: n.value, target: o, format: a.value };
2414
+ }
2415
+ function P(e, r, t) {
2416
+ if (typeof e == "string")
2417
+ return e;
2418
+ if (typeof e == "number") {
2419
+ if (!Number.isFinite(e)) {
2420
+ f(t, r, "Expected a finite number.");
2421
+ return;
2422
+ }
2423
+ return e;
2424
+ }
2425
+ const n = je(e, r, t);
2426
+ if (n) return n;
2427
+ f(
2428
+ t,
2429
+ r,
2430
+ "Expected a string, number, or structured numeric value."
2431
+ );
2432
+ }
2433
+ function Kr(e, r, t) {
2434
+ if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean")
2435
+ return typeof e == "string" && e.length > y.contentCell ? (f(
2436
+ t,
2437
+ r,
2438
+ `Must be ${y.contentCell} characters or fewer.`
2439
+ ), e.slice(0, y.contentCell)) : typeof e == "number" && !Number.isFinite(e) ? (f(t, r, "Expected a finite number."), null) : e;
2440
+ const n = je(e, r, t);
2441
+ return n || (f(
2442
+ t,
2443
+ r,
2444
+ "Expected a string, number, boolean, structured numeric value, or null."
2445
+ ), null);
2446
+ }
2447
+ function Nr(e, r, t) {
2448
+ if (!Array.isArray(e))
2449
+ return f(t, r, "Expected an array."), [];
2450
+ e.length === 0 && f(t, r, "Expected at least one column."), e.length > _.maxTableColumns && f(
2451
+ t,
2452
+ r,
2453
+ `Must have ${_.maxTableColumns} columns or fewer.`
2454
+ );
2455
+ const n = /* @__PURE__ */ new Set();
2456
+ return e.slice(0, _.maxTableColumns).map((o, a) => {
2457
+ const i = `${r}.${a}`, l = k(o, i, t);
2458
+ b(l, i, ["key", "label", "kind", "align"], t);
2459
+ const m = C(
2460
+ l.key,
2461
+ `${i}.key`,
2462
+ y.id,
2463
+ t
2464
+ );
2465
+ m && (n.has(m) && f(t, `${i}.key`, "Column key must be unique."), n.add(m));
2466
+ const c = C(
2467
+ l.label,
2468
+ `${i}.label`,
2469
+ y.contentTitle,
2470
+ t
2471
+ ), s = D(
2472
+ l.kind,
2473
+ `${i}.kind`,
2474
+ Sr,
2475
+ "text, number, currency, percent, date, or boolean",
2476
+ t
2477
+ ), u = D(
2478
+ l.align,
2479
+ `${i}.align`,
2480
+ _r,
2481
+ "left, center, or right",
2482
+ t
2483
+ );
2484
+ return {
2485
+ key: m,
2486
+ label: c,
2487
+ ...s ? { kind: s } : {},
2488
+ ...u ? { align: u } : {}
2489
+ };
2490
+ });
2491
+ }
2492
+ function zr(e, r, t, n) {
2493
+ if (!Array.isArray(e))
2494
+ return f(n, r, "Expected an array."), [];
2495
+ e.length > _.maxTableRows && f(
2496
+ n,
2497
+ r,
2498
+ `Must have ${_.maxTableRows} rows or fewer.`
2499
+ );
2500
+ const o = new Set(t.map((a) => a.key).filter(Boolean));
2501
+ return e.slice(0, _.maxTableRows).map((a, i) => {
2502
+ const l = `${r}.${i}`, m = k(a, l, n);
2503
+ return Object.keys(m).forEach((c) => {
2504
+ o.has(c) || f(n, `${l}.${c}`, `Unexpected table cell "${c}".`);
2505
+ }), Object.fromEntries(
2506
+ t.map((c) => [
2507
+ c.key,
2508
+ Kr(m[c.key] ?? null, `${l}.${c.key}`, n)
2509
+ ])
2510
+ );
2511
+ });
2512
+ }
2513
+ function Vr(e, r, t) {
2514
+ const n = `content.blocks.${r}`, o = k(e, n, t), a = o.type;
2515
+ if (a === "heading") {
2516
+ b(o, n, ["type", "text", "level", "evidenceIds"], t);
2517
+ const i = o.level === void 0 || o.level === null ? void 0 : o.level === 2 || o.level === 3 ? o.level : void 0;
2518
+ o.level !== void 0 && o.level !== null && i === void 0 && f(t, `${n}.level`, "Expected 2 or 3.");
2519
+ const l = R(o.evidenceIds, `${n}.evidenceIds`, t);
2520
+ return {
2521
+ type: "heading",
2522
+ text: C(
2523
+ o.text,
2524
+ `${n}.text`,
2525
+ y.contentTitle,
2526
+ t
2527
+ ),
2528
+ ...i ? { level: i } : {},
2529
+ ...l ? { evidenceIds: l } : {}
2530
+ };
2531
+ }
2532
+ if (a === "paragraph") {
2533
+ b(o, n, ["type", "text", "evidenceIds"], t);
2534
+ const i = R(o.evidenceIds, `${n}.evidenceIds`, t);
2535
+ return {
2536
+ type: "paragraph",
2537
+ text: C(
2538
+ o.text,
2539
+ `${n}.text`,
2540
+ y.contentText,
2541
+ t
2542
+ ),
2543
+ ...i ? { evidenceIds: i } : {}
2544
+ };
2545
+ }
2546
+ if (a === "finding") {
2547
+ b(o, n, ["type", "title", "text", "severity", "evidenceIds"], t);
2548
+ const i = T(
2549
+ o.title,
2550
+ `${n}.title`,
2551
+ y.contentTitle,
2552
+ t
2553
+ ), l = D(
2554
+ o.severity,
2555
+ `${n}.severity`,
2556
+ xr,
2557
+ "info, positive, warning, or critical",
2558
+ t
2559
+ );
2560
+ return {
2561
+ type: "finding",
2562
+ ...i ? { title: i } : {},
2563
+ text: C(
2564
+ o.text,
2565
+ `${n}.text`,
2566
+ y.contentText,
2567
+ t
2568
+ ),
2569
+ ...l ? { severity: l } : {},
2570
+ evidenceIds: R(o.evidenceIds, `${n}.evidenceIds`, t, {
2571
+ required: !0
2572
+ }) ?? []
2573
+ };
2574
+ }
2575
+ if (a === "bullets" || a === "actions" || a === "limitations") {
2576
+ b(o, n, ["type", "title", "items", "evidenceIds"], t);
2577
+ const i = T(
2578
+ o.title,
2579
+ `${n}.title`,
2580
+ y.contentTitle,
2581
+ t
2582
+ ), l = R(o.evidenceIds, `${n}.evidenceIds`, t);
2583
+ return {
2584
+ type: a,
2585
+ ...i ? { title: i } : {},
2586
+ items: Dr(o.items, `${n}.items`, t),
2587
+ ...l ? { evidenceIds: l } : {}
2588
+ };
2589
+ }
2590
+ if (a === "metric") {
2591
+ b(
2592
+ o,
2593
+ n,
2594
+ [
2595
+ "type",
2596
+ "label",
2597
+ "value",
2598
+ "previousValue",
2599
+ "delta",
2600
+ "percentChange",
2601
+ "unit",
2602
+ "evidenceIds"
2603
+ ],
2604
+ t
2605
+ );
2606
+ const i = P(o.value, `${n}.value`, t) ?? "";
2607
+ i === "" && f(
2608
+ t,
2609
+ `${n}.value`,
2610
+ "Expected a non-empty string, number, or structured numeric value."
2611
+ );
2612
+ const l = o.previousValue === void 0 || o.previousValue === null ? o.previousValue : P(
2613
+ o.previousValue,
2614
+ `${n}.previousValue`,
2615
+ t
2616
+ ), m = o.delta === void 0 || o.delta === null ? o.delta : P(
2617
+ o.delta,
2618
+ `${n}.delta`,
2619
+ t
2620
+ ), c = o.percentChange === void 0 || o.percentChange === null ? o.percentChange : P(
2621
+ o.percentChange,
2622
+ `${n}.percentChange`,
2623
+ t
2624
+ ), s = T(
2625
+ o.unit,
2626
+ `${n}.unit`,
2627
+ y.contentTitle,
2628
+ t
2629
+ ), u = R(o.evidenceIds, `${n}.evidenceIds`, t);
2630
+ return {
2631
+ type: "metric",
2632
+ label: C(
2633
+ o.label,
2634
+ `${n}.label`,
2635
+ y.contentTitle,
2636
+ t
2637
+ ),
2638
+ value: i,
2639
+ ...l !== void 0 ? { previousValue: l } : {},
2640
+ ...m !== void 0 ? { delta: m } : {},
2641
+ ...c !== void 0 ? { percentChange: c } : {},
2642
+ ...s ? { unit: s } : {},
2643
+ ...u ? { evidenceIds: u } : {}
2644
+ };
2645
+ }
2646
+ if (a === "kpi_grid") {
2647
+ b(o, n, ["type", "title", "tiles", "evidenceIds"], t);
2648
+ const i = T(
2649
+ o.title,
2650
+ `${n}.title`,
2651
+ y.contentTitle,
2652
+ t
2653
+ ), l = Array.isArray(o.tiles) ? o.tiles : [];
2654
+ Array.isArray(o.tiles) || f(t, `${n}.tiles`, "Expected an array."), l.length === 0 && f(t, `${n}.tiles`, "Expected at least one tile."), l.length > _.maxKpiTiles && f(
2655
+ t,
2656
+ `${n}.tiles`,
2657
+ `Must have ${_.maxKpiTiles} tiles or fewer.`
2658
+ );
2659
+ const m = l.slice(0, _.maxKpiTiles).map((s, u) => {
2660
+ const p = `${n}.tiles.${u}`, d = k(s, p, t);
2661
+ b(
2662
+ d,
2663
+ p,
2664
+ [
2665
+ "label",
2666
+ "value",
2667
+ "previousValue",
2668
+ "delta",
2669
+ "percentChange",
2670
+ "unit",
2671
+ "evidenceIds"
2672
+ ],
2673
+ t
2674
+ );
2675
+ const v = P(
2676
+ d.value,
2677
+ `${p}.value`,
2678
+ t
2679
+ ) ?? "";
2680
+ v === "" && f(
2681
+ t,
2682
+ `${p}.value`,
2683
+ "Expected a non-empty string, number, or structured numeric value."
2684
+ );
2685
+ const h = d.previousValue === void 0 || d.previousValue === null ? d.previousValue : P(
2686
+ d.previousValue,
2687
+ `${p}.previousValue`,
2688
+ t
2689
+ ), I = d.delta === void 0 || d.delta === null ? d.delta : P(
2690
+ d.delta,
2691
+ `${p}.delta`,
2692
+ t
2693
+ ), w = d.percentChange === void 0 || d.percentChange === null ? d.percentChange : P(
2694
+ d.percentChange,
2695
+ `${p}.percentChange`,
2696
+ t
2697
+ ), g = T(
2698
+ d.unit,
2699
+ `${p}.unit`,
2700
+ y.contentTitle,
2701
+ t
2702
+ ), $ = R(
2703
+ d.evidenceIds,
2704
+ `${p}.evidenceIds`,
2705
+ t
2706
+ );
2707
+ return {
2708
+ label: C(
2709
+ d.label,
2710
+ `${p}.label`,
2711
+ y.contentTitle,
2712
+ t
2713
+ ),
2714
+ value: v,
2715
+ ...h !== void 0 ? { previousValue: h } : {},
2716
+ ...I !== void 0 ? { delta: I } : {},
2717
+ ...w !== void 0 ? { percentChange: w } : {},
2718
+ ...g ? { unit: g } : {},
2719
+ ...$ ? { evidenceIds: $ } : {}
2720
+ };
2721
+ }), c = R(
2722
+ o.evidenceIds,
2723
+ `${n}.evidenceIds`,
2724
+ t
2725
+ );
2726
+ return {
2727
+ type: "kpi_grid",
2728
+ ...i ? { title: i } : {},
2729
+ tiles: m,
2730
+ ...c ? { evidenceIds: c } : {}
2731
+ };
2732
+ }
2733
+ if (a === "progress") {
2734
+ b(o, n, ["type", "label", "value", "detail", "evidenceIds"], t);
2735
+ const i = typeof o.value == "number" && Number.isFinite(o.value) ? o.value : 0;
2736
+ (typeof o.value != "number" || !Number.isFinite(o.value)) && f(t, `${n}.value`, "Expected a finite number.");
2737
+ const l = T(
2738
+ o.detail,
2739
+ `${n}.detail`,
2740
+ y.contentText,
2741
+ t
2742
+ ), m = R(o.evidenceIds, `${n}.evidenceIds`, t);
2743
+ return {
2744
+ type: "progress",
2745
+ label: C(
2746
+ o.label,
2747
+ `${n}.label`,
2748
+ y.contentTitle,
2749
+ t
2750
+ ),
2751
+ value: i,
2752
+ ...l ? { detail: l } : {},
2753
+ ...m ? { evidenceIds: m } : {}
2754
+ };
2755
+ }
2756
+ if (a === "table") {
2757
+ b(
2758
+ o,
2759
+ n,
2760
+ ["type", "id", "title", "columns", "rows", "caption", "totalRows", "evidenceIds"],
2761
+ t
2762
+ );
2763
+ const i = Nr(o.columns, `${n}.columns`, t), l = T(
2764
+ o.title,
2765
+ `${n}.title`,
2766
+ y.contentTitle,
2767
+ t
2768
+ ), m = T(
2769
+ o.id,
2770
+ `${n}.id`,
2771
+ y.id,
2772
+ t
2773
+ ), c = T(
2774
+ o.caption,
2775
+ `${n}.caption`,
2776
+ y.contentItem,
2777
+ t
2778
+ ), s = Ar(
2779
+ o.totalRows,
2780
+ `${n}.totalRows`,
2781
+ t
2782
+ ), u = R(o.evidenceIds, `${n}.evidenceIds`, t);
2783
+ return {
2784
+ type: "table",
2785
+ ...m ? { id: m } : {},
2786
+ ...l ? { title: l } : {},
2787
+ columns: i,
2788
+ rows: zr(o.rows, `${n}.rows`, i, t),
2789
+ ...c ? { caption: c } : {},
2790
+ ...s !== void 0 ? { totalRows: s } : {},
2791
+ ...u ? { evidenceIds: u } : {}
2792
+ };
2793
+ }
2794
+ if (a === "evidence_appendix") {
2795
+ b(o, n, ["type", "title", "evidenceIds"], t);
2796
+ const i = T(
2797
+ o.title,
2798
+ `${n}.title`,
2799
+ y.contentTitle,
2800
+ t
2801
+ );
2802
+ return {
2803
+ type: "evidence_appendix",
2804
+ ...i ? { title: i } : {},
2805
+ evidenceIds: R(o.evidenceIds, `${n}.evidenceIds`, t, {
2806
+ required: !0
2807
+ }) ?? []
2808
+ };
2809
+ }
2810
+ if (a === "sql") {
2811
+ b(o, n, ["type", "title", "sql", "evidenceIds"], t);
2812
+ const i = T(
2813
+ o.title,
2814
+ `${n}.title`,
2815
+ y.contentTitle,
2816
+ t
2817
+ ), l = C(
2818
+ o.sql,
2819
+ `${n}.sql`,
2820
+ y.contentSql,
2821
+ t
2822
+ ), m = R(o.evidenceIds, `${n}.evidenceIds`, t);
2823
+ return {
2824
+ type: "sql",
2825
+ ...i ? { title: i } : {},
2826
+ sql: l,
2827
+ ...m ? { evidenceIds: m } : {}
2828
+ };
2829
+ }
2830
+ return f(
2831
+ t,
2832
+ `${n}.type`,
2833
+ "Expected heading, paragraph, finding, bullets, metric, kpi_grid, progress, table, actions, limitations, sql, or evidence_appendix."
2834
+ ), {
2835
+ type: "paragraph",
2836
+ text: ""
2837
+ };
2838
+ }
2839
+ function Lr(e) {
2840
+ const r = [], t = k(e, "content", r);
2841
+ b(t, "content", ["version", "title", "summary", "blocks"], r), t.version !== 1 && f(r, "content.version", "Expected version 1.");
2842
+ const n = T(
2843
+ t.title,
2844
+ "content.title",
2845
+ y.contentTitle,
2846
+ r
2847
+ ), o = T(
2848
+ t.summary,
2849
+ "content.summary",
2850
+ y.contentSummary,
2851
+ r
2852
+ );
2853
+ Array.isArray(t.blocks) || f(r, "content.blocks", "Expected an array.");
2854
+ const a = Array.isArray(t.blocks) ? t.blocks : [];
2855
+ a.length === 0 && f(r, "content.blocks", "Expected at least one block."), a.length > _.maxBlocks && f(
2856
+ r,
2857
+ "content.blocks",
2858
+ `Must have ${_.maxBlocks} blocks or fewer.`
2859
+ );
2860
+ const i = a.slice(0, _.maxBlocks).map((l, m) => Vr(l, m, r));
2861
+ return ye(r), {
2862
+ version: 1,
2863
+ ...n ? { title: n } : {},
2864
+ ...o ? { summary: o } : {},
2865
+ blocks: i
2866
+ };
2867
+ }
2868
+ function qn(e) {
2869
+ try {
2870
+ return {
2871
+ valid: !0,
2872
+ value: Lr(e),
2873
+ issues: []
2874
+ };
2875
+ } catch (r) {
2876
+ if (r instanceof X)
2877
+ return { valid: !1, issues: r.issues };
2878
+ throw r;
2879
+ }
2880
+ }
2881
+ function Y(e, r, t, n) {
2882
+ return typeof e == "string" && t.includes(e) ? e : (f(n, r, `Expected ${t.join(" or ")}.`), t[0]);
2883
+ }
2884
+ function D(e, r, t, n, o) {
2885
+ if (e != null) {
2886
+ if (typeof e == "string" && t.has(e))
2887
+ return e;
2888
+ f(o, r, `Expected ${n}.`);
2889
+ }
2890
+ }
2891
+ function Ur(e, r, t) {
2892
+ if (e != null) {
2893
+ if (!Array.isArray(e)) {
2894
+ f(t, r, "Expected an array.");
2895
+ return;
2896
+ }
2897
+ return e;
2898
+ }
2899
+ }
2900
+ function jr(e, r, t) {
2901
+ if (e != null) {
2902
+ if (!ze(e)) {
2903
+ f(t, r, "Expected an object.");
2904
+ return;
2905
+ }
2906
+ return e;
2907
+ }
2908
+ }
2909
+ function qr(e, r, t) {
2910
+ if (e == null)
2911
+ return;
2912
+ const n = k(e, r, t);
2913
+ b(n, r, Fr, t);
2914
+ const o = {}, a = D(
2915
+ n.pageSize,
2916
+ `${r}.pageSize`,
2917
+ Cr,
2918
+ "letter, legal, a4, a3, or tabloid",
2919
+ t
2920
+ ), i = D(
2921
+ n.orientation,
2922
+ `${r}.orientation`,
2923
+ Tr,
2924
+ "portrait or landscape",
2925
+ t
2926
+ ), l = D(
2927
+ n.delimiter,
2928
+ `${r}.delimiter`,
2929
+ $r,
2930
+ "comma, semicolon, or tab",
2931
+ t
2932
+ ), m = D(
2933
+ n.sheetSelection,
2934
+ `${r}.sheetSelection`,
2935
+ kr,
2936
+ "current or all",
2937
+ t
2938
+ );
2939
+ a && (o.pageSize = a), i && (o.orientation = i), l && (o.delimiter = l), m && (o.sheetSelection = m);
2940
+ for (const c of [
2941
+ "includeFilters",
2942
+ "includeTimestamp",
2943
+ "includeHeaders",
2944
+ "useFormattedValues",
2945
+ "allowDownload"
2946
+ ])
2947
+ if (!(n[c] === void 0 || n[c] === null)) {
2948
+ if (typeof n[c] != "boolean") {
2949
+ f(t, `${r}.${c}`, "Expected a boolean.");
2950
+ continue;
2951
+ }
2952
+ o[c] = n[c];
2953
+ }
2954
+ for (const c of [
2955
+ "currentSheetId",
2956
+ "currentSheetName",
2957
+ "filterLine",
2958
+ "selectedSheetId",
2959
+ "cardType",
2960
+ "theme"
2961
+ ]) {
2962
+ const s = T(
2963
+ n[c],
2964
+ `${r}.${c}`,
2965
+ y.id,
2966
+ t
2967
+ );
2968
+ s && (o[c] = s);
2969
+ }
2970
+ for (const c of [
2971
+ "filterValues",
2972
+ "inlineFilterValues",
2973
+ "sheetFilterValues",
2974
+ "controlDefinitions",
2975
+ "cardControlDefinitions",
2976
+ "controlBindings"
2977
+ ]) {
2978
+ const s = Ur(n[c], `${r}.${c}`, t);
2979
+ s && (o[c] = s);
2980
+ }
2981
+ for (const c of [
2982
+ "controlValues",
2983
+ "tablePreferences",
2984
+ "dashboardInputExecutionSnapshot"
2985
+ ]) {
2986
+ const s = jr(n[c], `${r}.${c}`, t);
2987
+ s && (o[c] = s);
2988
+ }
2989
+ return Object.keys(o).length > 0 ? o : void 0;
2990
+ }
2991
+ function ne(e, r, t, n) {
2992
+ const o = T(
2993
+ r,
2994
+ t,
2995
+ y.attachmentTitle,
2996
+ n
2997
+ );
2998
+ return o && (e.title = o), e;
2999
+ }
3000
+ function oe(e, r, t, n) {
3001
+ const o = qr(r, t, n);
3002
+ return o && (e.settings = o), e;
3003
+ }
3004
+ function Gr(e, r, t) {
3005
+ const n = `attachments.${r}`, o = k(e, n, t), a = o.type;
3006
+ if (a === "dashboard") {
3007
+ b(
3008
+ o,
3009
+ n,
3010
+ ["type", "dashboardId", "format", "title", "settings"],
3011
+ t
3012
+ );
3013
+ const i = ne(
3014
+ {
3015
+ type: "dashboard",
3016
+ dashboardId: C(
3017
+ o.dashboardId,
3018
+ `${n}.dashboardId`,
3019
+ y.id,
3020
+ t
3021
+ ),
3022
+ format: Y(o.format, `${n}.format`, ["pdf"], t)
3023
+ },
3024
+ o.title,
3025
+ `${n}.title`,
3026
+ t
3027
+ );
3028
+ return oe(i, o.settings, `${n}.settings`, t);
3029
+ }
3030
+ if (a === "dashboard_sheet" || a === "document_sheet") {
3031
+ b(
3032
+ o,
3033
+ n,
3034
+ ["type", "dashboardId", "sheetId", "format", "title", "settings"],
3035
+ t
3036
+ );
3037
+ const i = ne(
3038
+ {
3039
+ type: a,
3040
+ dashboardId: C(
3041
+ o.dashboardId,
3042
+ `${n}.dashboardId`,
3043
+ y.id,
3044
+ t
3045
+ ),
3046
+ sheetId: C(
3047
+ o.sheetId,
3048
+ `${n}.sheetId`,
3049
+ y.id,
3050
+ t
3051
+ ),
3052
+ format: Y(o.format, `${n}.format`, ["pdf"], t)
3053
+ },
3054
+ o.title,
3055
+ `${n}.title`,
3056
+ t
3057
+ );
3058
+ return oe(i, o.settings, `${n}.settings`, t);
3059
+ }
3060
+ if (a === "card") {
3061
+ b(
3062
+ o,
3063
+ n,
3064
+ ["type", "dashboardId", "cardId", "format", "title", "settings"],
3065
+ t
3066
+ );
3067
+ const i = ne(
3068
+ {
3069
+ type: "card",
3070
+ dashboardId: C(
3071
+ o.dashboardId,
3072
+ `${n}.dashboardId`,
3073
+ y.id,
3074
+ t
3075
+ ),
3076
+ cardId: C(
3077
+ o.cardId,
3078
+ `${n}.cardId`,
3079
+ y.id,
3080
+ t
3081
+ ),
3082
+ format: Y(
3083
+ o.format,
3084
+ `${n}.format`,
3085
+ ["csv", "pdf"],
3086
+ t
3087
+ )
3088
+ },
3089
+ o.title,
3090
+ `${n}.title`,
3091
+ t
3092
+ );
3093
+ return oe(i, o.settings, `${n}.settings`, t);
3094
+ }
3095
+ return f(
3096
+ t,
3097
+ `${n}.type`,
3098
+ "Expected dashboard, dashboard_sheet, document_sheet, or card."
3099
+ ), { type: "dashboard", dashboardId: "", format: "pdf" };
3100
+ }
3101
+ function Hr(e) {
3102
+ switch (e.type) {
3103
+ case "dashboard":
3104
+ return `${e.type}:${e.dashboardId}:${e.format}`;
3105
+ case "dashboard_sheet":
3106
+ case "document_sheet":
3107
+ return `${e.type}:${e.dashboardId}:${e.sheetId}:${e.format}`;
3108
+ case "card":
3109
+ return `${e.type}:${e.dashboardId}:${e.cardId}:${e.format}`;
3110
+ }
3111
+ }
3112
+ function qe(e, r) {
3113
+ if (e == null)
3114
+ return [];
3115
+ if (!Array.isArray(e))
3116
+ return f(r, "attachments", "Expected an array."), [];
3117
+ e.length > te && f(
3118
+ r,
3119
+ "attachments",
3120
+ `Choose ${te} attachments or fewer.`
3121
+ );
3122
+ const t = e.slice(0, te).map((o, a) => Gr(o, a, r)), n = /* @__PURE__ */ new Set();
3123
+ return t.forEach((o, a) => {
3124
+ const i = Hr(o);
3125
+ n.has(i) && f(r, `attachments.${a}`, "Duplicate attachment."), n.add(i);
3126
+ }), t;
3127
+ }
3128
+ function Ge(e, r) {
3129
+ if (e == null)
3130
+ return;
3131
+ const t = k(e, "limits", r);
3132
+ b(t, "limits", Object.keys(re), r);
3133
+ const n = {};
3134
+ return Object.keys(re).forEach((o) => {
3135
+ const a = t[o];
3136
+ if (a == null)
3137
+ return;
3138
+ const i = re[o];
3139
+ if (typeof a != "number" || !Number.isInteger(a) || a < i.min || a > i.max) {
3140
+ f(
3141
+ r,
3142
+ `limits.${o}`,
3143
+ `Expected an integer between ${i.min} and ${i.max}.`
3144
+ );
3145
+ return;
3146
+ }
3147
+ n[o] = a;
3148
+ }), Object.keys(n).length > 0 ? n : void 0;
3149
+ }
3150
+ function ye(e) {
3151
+ if (e.length > 0)
3152
+ throw new X(e);
3153
+ }
3154
+ function He(e, r, t) {
3155
+ !(e.type === "generated_analysis" || e.type === "custom_message" && !!e.message.trim()) && r.length === 0 && f(
3156
+ t,
3157
+ "body",
3158
+ "Add briefing instructions, a custom message, or at least one attachment."
3159
+ );
3160
+ }
3161
+ function Wr(e, r, t) {
3162
+ e == null || e.forEach((n, o) => {
3163
+ const a = `${t}.${o}.scope`, i = n.scope.attachmentIndex;
3164
+ if (i === void 0)
3165
+ throw new U(
3166
+ `${a}.attachmentIndex must identify the attachment that owns this presentation entry.`
3167
+ );
3168
+ const l = r[i];
3169
+ if (!l)
3170
+ throw new U(
3171
+ `${a}.attachmentIndex must identify an existing attachment.`
3172
+ );
3173
+ if (n.scope.dashboardId !== l.dashboardId)
3174
+ throw new U(
3175
+ `${a}.dashboardId must match the dashboard selected by the referenced attachment.`
3176
+ );
3177
+ if (l.type === "card" && n.scope.cardId !== l.cardId)
3178
+ throw new U(
3179
+ `${a}.cardId must match the card selected by the referenced attachment.`
3180
+ );
3181
+ });
3182
+ }
3183
+ function We(e) {
3184
+ const r = [], t = k(e, "jobConfig", r);
3185
+ b(
3186
+ t,
3187
+ "jobConfig",
3188
+ [
3189
+ "kind",
3190
+ "presentationExecutionSnapshot",
3191
+ "source",
3192
+ "body",
3193
+ "attachments",
3194
+ "presentation",
3195
+ "limits"
3196
+ ],
3197
+ r
3198
+ ), t.kind !== ce && f(r, "kind", "Expected BRIEFING.");
3199
+ let n;
3200
+ try {
3201
+ n = lt(
3202
+ t.presentationExecutionSnapshot
3203
+ );
3204
+ } catch (c) {
3205
+ if (c instanceof U)
3206
+ throw c;
3207
+ f(
3208
+ r,
3209
+ "jobConfig.presentationExecutionSnapshot",
3210
+ c instanceof Error ? c.message : "Invalid presentation snapshot."
3211
+ );
3212
+ }
3213
+ const o = Ve(t.source, r), a = Le(t.body, r), i = qe(t.attachments, r), l = Ue(t.presentation, r), m = Ge(t.limits, r);
3214
+ return He(a, i, r), Wr(
3215
+ n == null ? void 0 : n.resolvedFormats,
3216
+ i,
3217
+ "jobConfig.presentationExecutionSnapshot.resolvedFormats"
3218
+ ), ye(r), {
3219
+ kind: ce,
3220
+ presentationExecutionSnapshot: n,
3221
+ source: o,
3222
+ body: a,
3223
+ attachments: i,
3224
+ presentation: l,
3225
+ ...m ? { limits: m } : {}
3226
+ };
3227
+ }
3228
+ function Gn(e) {
3229
+ return We({
3230
+ ...e,
3231
+ kind: ce
3232
+ });
3233
+ }
3234
+ function he(e, r, t, n = "deliveryConfig.recipients") {
3235
+ const o = `${n}.${r}`, a = k(e, o, t), i = a.type;
3236
+ if (i === "email") {
3237
+ b(a, o, ["type", "address", "name"], t);
3238
+ const l = C(
3239
+ a.address,
3240
+ `${o}.address`,
3241
+ y.id,
3242
+ t
3243
+ ), m = T(
3244
+ a.name,
3245
+ `${o}.name`,
3246
+ y.attachmentTitle,
3247
+ t
3248
+ );
3249
+ return l && !Pr(l) && f(t, `${o}.address`, "Email address is invalid."), {
3250
+ type: "email",
3251
+ address: l,
3252
+ ...m ? { name: m } : {}
3253
+ };
3254
+ }
3255
+ return i === "user" ? (b(a, o, ["type", "userId"], t), {
3256
+ type: "user",
3257
+ userId: C(
3258
+ a.userId,
3259
+ `${o}.userId`,
3260
+ y.id,
3261
+ t
3262
+ )
3263
+ }) : i === "tenant_user" ? (b(a, o, ["type", "tenantUserId"], t), {
3264
+ type: "tenant_user",
3265
+ tenantUserId: C(
3266
+ a.tenantUserId,
3267
+ `${o}.tenantUserId`,
3268
+ y.id,
3269
+ t
3270
+ )
3271
+ }) : i === "group" ? (b(a, o, ["type", "groupId"], t), {
3272
+ type: "group",
3273
+ groupId: C(
3274
+ a.groupId,
3275
+ `${o}.groupId`,
3276
+ y.id,
3277
+ t
3278
+ )
3279
+ }) : (f(
3280
+ t,
3281
+ `${o}.type`,
3282
+ "Expected email, user, tenant_user, or group."
3283
+ ), { type: "email", address: "" });
3284
+ }
3285
+ function Yr(e, r) {
3286
+ return e == null ? [] : Array.isArray(e) ? e.map(
3287
+ (t, n) => he(t, n, r)
3288
+ ) : (f(r, "deliveryConfig.recipients", "Expected an array."), []);
3289
+ }
3290
+ function Zr(e, r) {
3291
+ if (!Array.isArray(e))
3292
+ return f(r, "deliveryConfig.channels", "Expected an array."), [];
3293
+ const t = [];
3294
+ return e.forEach((n, o) => {
3295
+ if (!Ye(n)) {
3296
+ f(
3297
+ r,
3298
+ `deliveryConfig.channels.${o}`,
3299
+ "Expected EMAIL, WEBHOOK, SLACK, IN_APP, or TELEGRAM."
3300
+ );
3301
+ return;
3302
+ }
3303
+ t.includes(n) || t.push(n);
3304
+ }), t;
3305
+ }
3306
+ function Jr(e, r, t) {
3307
+ if (e == null)
3308
+ return;
3309
+ const n = k(e, r, t), o = {};
3310
+ return Object.entries(n).forEach(([a, i]) => {
3311
+ if (typeof i != "string") {
3312
+ f(t, `${r}.${a}`, "Expected a string.");
3313
+ return;
3314
+ }
3315
+ o[a] = i.trim();
3316
+ }), Object.keys(o).length > 0 ? o : void 0;
3317
+ }
3318
+ function Qr(e, r, t) {
3319
+ if (e == null)
3320
+ return;
3321
+ const n = k(e, r, t);
3322
+ b(
3323
+ n,
3324
+ r,
3325
+ ["url", "method", "headers", "secretEncrypted"],
3326
+ t
3327
+ );
3328
+ const o = n.method === void 0 || n.method === null ? void 0 : Y(n.method, `${r}.method`, ["POST", "PUT"], t), a = Jr(n.headers, `${r}.headers`, t), i = T(
3329
+ n.secretEncrypted,
3330
+ `${r}.secretEncrypted`,
3331
+ 2e3,
3332
+ t
3333
+ );
3334
+ return {
3335
+ url: C(n.url, `${r}.url`, 2e3, t),
3336
+ ...o ? { method: o } : {},
3337
+ ...a ? { headers: a } : {},
3338
+ ...i ? { secretEncrypted: i } : {}
3339
+ };
3340
+ }
3341
+ function Xr(e, r, t) {
3342
+ const n = k(e, r, t), o = n.type;
3343
+ if (o === "channel") {
3344
+ b(
3345
+ n,
3346
+ r,
3347
+ ["type", "channelId", "channelName", "isPrivate"],
3348
+ t
3349
+ );
3350
+ const a = T(
3351
+ n.channelName,
3352
+ `${r}.channelName`,
3353
+ y.attachmentTitle,
3354
+ t
3355
+ ), i = n.isPrivate === void 0 || n.isPrivate === null ? void 0 : N(
3356
+ n.isPrivate,
3357
+ !1,
3358
+ `${r}.isPrivate`,
3359
+ t
3360
+ );
3361
+ return {
3362
+ type: "channel",
3363
+ channelId: C(
3364
+ n.channelId,
3365
+ `${r}.channelId`,
3366
+ y.id,
3367
+ t
3368
+ ),
3369
+ ...a ? { channelName: a } : {},
3370
+ ...i !== void 0 ? { isPrivate: i } : {}
3371
+ };
3372
+ }
3373
+ return o === "dm" ? (b(n, r, ["type", "recipient"], t), f(
3374
+ t,
3375
+ `${r}.type`,
3376
+ "Slack DM delivery is not supported in V1."
3377
+ ), {
3378
+ type: "dm",
3379
+ recipient: he(n.recipient, 0, t, `${r}.recipient`)
3380
+ }) : (f(t, `${r}.type`, "Expected channel."), { type: "channel", channelId: "" });
3381
+ }
3382
+ function en(e, r, t) {
3383
+ if (e == null)
3384
+ return;
3385
+ if (!Array.isArray(e)) {
3386
+ f(t, r, "Expected an array.");
3387
+ return;
3388
+ }
3389
+ const n = e.map(
3390
+ (o, a) => he(o, a, t, r)
3391
+ );
3392
+ return n.length > 0 ? n : void 0;
3393
+ }
3394
+ function tn(e, r, t) {
3395
+ if (e == null)
3396
+ return;
3397
+ const n = k(e, r, t);
3398
+ b(
3399
+ n,
3400
+ r,
3401
+ [
3402
+ "destination",
3403
+ "threadMentions",
3404
+ "postThreadDetail",
3405
+ "includeDashboardLink",
3406
+ "includeBriefingLink"
3407
+ ],
3408
+ t
3409
+ );
3410
+ const o = en(
3411
+ n.threadMentions,
3412
+ `${r}.threadMentions`,
3413
+ t
3414
+ ), a = N(
3415
+ n.postThreadDetail,
3416
+ !0,
3417
+ `${r}.postThreadDetail`,
3418
+ t
3419
+ ), i = N(
3420
+ n.includeDashboardLink,
3421
+ !0,
3422
+ `${r}.includeDashboardLink`,
3423
+ t
3424
+ ), l = N(
3425
+ n.includeBriefingLink,
3426
+ !0,
3427
+ `${r}.includeBriefingLink`,
3428
+ t
3429
+ );
3430
+ return {
3431
+ destination: Xr(
3432
+ n.destination,
3433
+ `${r}.destination`,
3434
+ t
3435
+ ),
3436
+ ...o ? { threadMentions: o } : {},
3437
+ ...n.postThreadDetail !== void 0 ? { postThreadDetail: a } : {},
3438
+ ...n.includeDashboardLink !== void 0 ? { includeDashboardLink: i } : {},
3439
+ ...n.includeBriefingLink !== void 0 ? { includeBriefingLink: l } : {}
3440
+ };
3441
+ }
3442
+ function rn(e, r, t) {
3443
+ const n = k(e, r, t);
3444
+ b(
3445
+ n,
3446
+ r,
3447
+ [
3448
+ "subjectOverride",
3449
+ "titleOverride",
3450
+ "summaryOverride",
3451
+ "actionBlockVisible",
3452
+ "formatProfile",
3453
+ "slackConfig",
3454
+ "webhookConfig"
3455
+ ],
3456
+ t
3457
+ );
3458
+ const o = D(
3459
+ n.formatProfile,
3460
+ `${r}.formatProfile`,
3461
+ Er,
3462
+ "concise, balanced, or detailed",
3463
+ t
3464
+ ), a = T(
3465
+ n.subjectOverride,
3466
+ `${r}.subjectOverride`,
3467
+ 500,
3468
+ t
3469
+ ), i = T(
3470
+ n.titleOverride,
3471
+ `${r}.titleOverride`,
3472
+ 500,
3473
+ t
3474
+ ), l = T(
3475
+ n.summaryOverride,
3476
+ `${r}.summaryOverride`,
3477
+ 2e3,
3478
+ t
3479
+ ), m = N(
3480
+ n.actionBlockVisible,
3481
+ !0,
3482
+ `${r}.actionBlockVisible`,
3483
+ t
3484
+ ), c = Qr(
3485
+ n.webhookConfig,
3486
+ `${r}.webhookConfig`,
3487
+ t
3488
+ ), s = tn(
3489
+ n.slackConfig,
3490
+ `${r}.slackConfig`,
3491
+ t
3492
+ );
3493
+ return {
3494
+ ...o ? { formatProfile: o } : {},
3495
+ ...a ? { subjectOverride: a } : {},
3496
+ ...i ? { titleOverride: i } : {},
3497
+ ...l ? { summaryOverride: l } : {},
3498
+ ...n.actionBlockVisible !== void 0 ? { actionBlockVisible: m } : {},
3499
+ ...s ? { slackConfig: s } : {},
3500
+ ...c ? { webhookConfig: c } : {}
3501
+ };
3502
+ }
3503
+ function nn(e, r) {
3504
+ if (e == null)
3505
+ return;
3506
+ const t = k(e, "deliveryConfig.channelConfigs", r), n = {};
3507
+ return Object.entries(t).forEach(([o, a]) => {
3508
+ if (!Ye(o)) {
3509
+ f(
3510
+ r,
3511
+ `deliveryConfig.channelConfigs.${o}`,
3512
+ "Expected a supported delivery channel."
3513
+ );
3514
+ return;
3515
+ }
3516
+ n[o] = rn(
3517
+ a,
3518
+ `deliveryConfig.channelConfigs.${o}`,
3519
+ r
3520
+ );
3521
+ }), Object.keys(n).length > 0 ? n : void 0;
3522
+ }
3523
+ function on(e, r) {
3524
+ var m, c, s;
3525
+ if (e == null)
3526
+ return null;
3527
+ const t = k(e, "deliveryConfig", r);
3528
+ b(
3529
+ t,
3530
+ "deliveryConfig",
3531
+ ["recipients", "channels", "channelConfigs"],
3532
+ r
3533
+ );
3534
+ const n = nn(t.channelConfigs, r), o = Yr(t.recipients, r), a = Zr(t.channels, r), i = ((c = (m = n == null ? void 0 : n.SLACK) == null ? void 0 : m.slackConfig) == null ? void 0 : c.destination.type) === "channel" && !!n.SLACK.slackConfig.destination.channelId.trim();
3535
+ return a.some(
3536
+ (u) => u !== "SLACK"
3537
+ ) && o.length === 0 && f(
3538
+ r,
3539
+ "deliveryConfig.recipients",
3540
+ "Add at least one recipient or remove delivery config."
3541
+ ), a.length === 0 && f(
3542
+ r,
3543
+ "deliveryConfig.channels",
3544
+ "Choose at least one delivery channel or remove delivery config."
3545
+ ), a.includes("SLACK") && !i && f(
3546
+ r,
3547
+ "deliveryConfig.channelConfigs.SLACK.slackConfig.destination.channelId",
3548
+ "Choose a Slack channel destination."
3549
+ ), !a.includes("SLACK") && ((s = n == null ? void 0 : n.SLACK) != null && s.slackConfig) && f(
3550
+ r,
3551
+ "deliveryConfig.channelConfigs.SLACK",
3552
+ "Slack config requires SLACK in deliveryConfig.channels."
3553
+ ), {
3554
+ recipients: o,
3555
+ channels: a,
3556
+ ...n ? { channelConfigs: n } : {}
3557
+ };
3558
+ }
3559
+ function ge(e) {
3560
+ const r = [], t = k(e, "draft", r);
3561
+ b(
3562
+ t,
3563
+ "draft",
3564
+ [
3565
+ "name",
3566
+ "description",
3567
+ "status",
3568
+ "scheduleExpr",
3569
+ "timezone",
3570
+ "source",
3571
+ "body",
3572
+ "attachments",
3573
+ "presentation",
3574
+ "limits",
3575
+ "deliveryConfig"
3576
+ ],
3577
+ r
3578
+ );
3579
+ const n = C(
3580
+ t.name,
3581
+ "name",
3582
+ y.name,
3583
+ r
3584
+ ), o = T(
3585
+ t.description,
3586
+ "description",
3587
+ y.description,
3588
+ r
3589
+ ) ?? null, a = T(t.scheduleExpr, "scheduleExpr", 500, r) ?? null, i = T(t.timezone, "timezone", 200, r) ?? "UTC", l = Br(t.status, r), m = Ve(t.source, r), c = Le(t.body, r), s = qe(t.attachments, r), u = Ue(t.presentation, r), p = Ge(t.limits, r), d = on(t.deliveryConfig, r);
3590
+ return He(c, s, r), ye(r), {
3591
+ name: n,
3592
+ description: o,
3593
+ status: l,
3594
+ scheduleExpr: a,
3595
+ timezone: i,
3596
+ source: m,
3597
+ body: c,
3598
+ attachments: s,
3599
+ presentation: u,
3600
+ ...p ? { limits: p } : {},
3601
+ deliveryConfig: d
3602
+ };
3603
+ }
3604
+ function Hn(e) {
3605
+ return ge(e);
3606
+ }
3607
+ function Wn(e) {
3608
+ return ge(e);
3609
+ }
3610
+ function Yn(e) {
3611
+ try {
3612
+ return { valid: !0, value: ge(e), issues: [] };
3613
+ } catch (r) {
3614
+ if (r instanceof X)
3615
+ return { valid: !1, issues: r.issues };
3616
+ throw r;
3617
+ }
3618
+ }
3619
+ function Zn(e) {
3620
+ try {
3621
+ return { valid: !0, value: We(e), issues: [] };
3622
+ } catch (r) {
3623
+ if (r instanceof X)
3624
+ return { valid: !1, issues: r.issues };
3625
+ throw r;
3626
+ }
3627
+ }
3628
+ function Jn(e) {
3629
+ return typeof e == "string" && Ne.has(e);
3630
+ }
3631
+ function Ye(e) {
3632
+ return typeof e == "string" && wr.has(e);
3633
+ }
3634
+ export {
3635
+ Pe as $,
3636
+ Mn as A,
3637
+ Q as B,
3638
+ Pt as C,
3639
+ bn as D,
3640
+ En as E,
3641
+ K as F,
3642
+ $n as G,
3643
+ xt as H,
3644
+ Rt as I,
3645
+ At as J,
3646
+ Be as K,
3647
+ me as L,
3648
+ Ot as M,
3649
+ Lt as N,
3650
+ Ut as O,
3651
+ wn as P,
3652
+ kn as Q,
3653
+ Nt as R,
3654
+ zn as S,
3655
+ pr as T,
3656
+ On as U,
3657
+ dr as V,
3658
+ Kn as W,
3659
+ Dn as X,
3660
+ hr as Y,
3661
+ Vn as Z,
3662
+ qt as _,
3663
+ Ln as a,
3664
+ Sn as a0,
3665
+ Et as a1,
3666
+ ce as a2,
3667
+ vr as a3,
3668
+ le as a4,
3669
+ te as a5,
3670
+ y as a6,
3671
+ _ as a7,
3672
+ br as a8,
3673
+ Ir as a9,
3674
+ jn as aa,
3675
+ X as ab,
3676
+ Lr as ac,
3677
+ qn as ad,
3678
+ We as ae,
3679
+ Gn as af,
3680
+ ge as ag,
3681
+ Hn as ah,
3682
+ Wn as ai,
3683
+ Yn as aj,
3684
+ Zn as ak,
3685
+ Jn as al,
3686
+ Ye as am,
3687
+ yr as an,
3688
+ gr as ao,
3689
+ Jt as b,
3690
+ Yt as c,
3691
+ Nn as d,
3692
+ Rn as e,
3693
+ Qt as f,
3694
+ Un as g,
3695
+ Bn as h,
3696
+ we as i,
3697
+ An as j,
3698
+ Zt as k,
3699
+ Pn as l,
3700
+ De as m,
3701
+ H as n,
3702
+ _n as o,
3703
+ fe as p,
3704
+ Fn as q,
3705
+ Xt as r,
3706
+ _t as s,
3707
+ vn as t,
3708
+ Tn as u,
3709
+ Ft as v,
3710
+ Cn as w,
3711
+ xn as x,
3712
+ In as y,
3713
+ Re as z
3714
+ };