react-semaphor 0.1.537 → 0.1.538

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 (173) hide show
  1. package/dist/analytics-protocol/index.js +352 -341
  2. package/dist/assistant-context/index.js +10 -0
  3. package/dist/assistant-protocol/index.js +104 -0
  4. package/dist/brand-studio/index.js +35 -31
  5. package/dist/briefings/index.js +46 -45
  6. package/dist/chunks/_commonjsHelpers-BkfeUUK-.js +28 -0
  7. package/dist/chunks/add-to-dashboard-CxtTfISD.js +56 -0
  8. package/dist/chunks/aggregate-table-row-presentation-Qgpv6_G8.js +979 -0
  9. package/dist/chunks/analytics-base-schemas-BFAoRlkU.js +472 -0
  10. package/dist/chunks/apply-dashboard-operations-C-iahGka.js +402 -0
  11. package/dist/chunks/assistant-chat-BAqUIFp5.js +7966 -0
  12. package/dist/chunks/availability-Bp5Gfu1I.js +44 -0
  13. package/dist/chunks/{bookmark-state-B-I9BDD0.js → bookmark-state-k7y5SNGf.js} +9 -9
  14. package/dist/chunks/{braces-8TRlDwDw.js → braces-o9UiRQes.js} +1 -1
  15. package/dist/chunks/calculated-field-identity-DcBS2NPP.js +2161 -0
  16. package/dist/chunks/calendar-day-equality-Bpl15IBo.js +487 -0
  17. package/dist/chunks/class-utils-Df1OVOT1.js +2315 -0
  18. package/dist/chunks/{field-dependencies-CpRUwr9J.js → common-types-CUf03Htv.js} +65 -58
  19. package/dist/chunks/context-HD9usB1P.js +349 -0
  20. package/dist/chunks/conversation-sQiWYUOb.js +16 -0
  21. package/dist/chunks/csv-utils-GUfKyT1J.js +56 -0
  22. package/dist/chunks/custom-visual-inputs-BrUOIwln.js +3288 -0
  23. package/dist/chunks/{dashboard-BPJo-Fnd.js → dashboard-DTDDFQsS.js} +1 -1
  24. package/dist/chunks/{dashboard-briefing-launcher-A2uVpHCp.js → dashboard-briefing-launcher-Bb2QUqOa.js} +764 -740
  25. package/dist/chunks/{dashboard-controls-DxTuVis_.js → dashboard-controls-FpONU8QV.js} +683 -686
  26. package/dist/chunks/{common-types-g7yS12Cg.js → dashboard-filter-value-compatibility-D95O4nd7.js} +18 -24
  27. package/dist/chunks/dashboard-json-DazPhBU_.js +69 -0
  28. package/dist/chunks/document-dashboard-inputs-D96rlU7S.js +10678 -0
  29. package/dist/chunks/document-sheet-utils-C1eEldxs.js +1076 -0
  30. package/dist/chunks/{edit-dashboard-visual-ByV0OwSp.js → edit-dashboard-visual-CIhZodVH.js} +4744 -4746
  31. package/dist/chunks/editor-draft-sync-BN5qYHPF.js +15 -0
  32. package/dist/chunks/filter-value-text-BhWugPWE.js +163 -0
  33. package/dist/chunks/index-CqMiAkay.js +3164 -0
  34. package/dist/chunks/index-CuHybtft.js +51 -0
  35. package/dist/chunks/layout-grid-Bgzth8vd.js +16 -0
  36. package/dist/chunks/{matrix-analytical-definition-CgBTD6H8.js → matrix-analytical-definition-bcprSe4u.js} +1 -1
  37. package/dist/chunks/{matrix-card-CAdizkUl.js → matrix-card-CJn1hB5V.js} +13 -12
  38. package/dist/chunks/matrix-definition-DQDI2okF.js +206 -0
  39. package/dist/chunks/{matrix-formatter-DJCk8Znf.js → matrix-formatter-Bgw32tb3.js} +648 -457
  40. package/dist/chunks/matrix-member-presentation-BNPSDKBG.js +105 -0
  41. package/dist/chunks/{matrix-operation-contract-BKupLHXL.js → matrix-operation-contract-B8PBF1Gd.js} +134 -133
  42. package/dist/chunks/{metric-comparison-BKHyvnAy.js → metric-comparison-CojWeLqx.js} +1 -1
  43. package/dist/chunks/{palette-Cp1hqZtm.js → palette-D10o_yYX.js} +1 -1
  44. package/dist/chunks/pivot-header-presentation-MkcKnjn3.js +42 -0
  45. package/dist/chunks/{pivot-result-identity-Bs4tLtLo.js → pivot-result-identity-D6hhcRXi.js} +1 -1
  46. package/dist/chunks/pivot-result-lifecycle-8qCDmpKc.js +804 -0
  47. package/dist/chunks/raw-temporal-D61lr48Y.js +1464 -0
  48. package/dist/chunks/{raw-temporal-contract-mLFS-9wk.js → raw-temporal-contract-C51YG48G.js} +1 -1
  49. package/dist/chunks/report-preferences-dialog-BCGs4-AE.js +1808 -0
  50. package/dist/chunks/{report-runtime-context-CG_I0PPW.js → report-runtime-context-B984Nq1E.js} +8 -7
  51. package/dist/chunks/save-CfJpQQ68.js +21 -0
  52. package/dist/chunks/saved-dashboard-context-BrTkjcod.js +566 -0
  53. package/dist/chunks/{selection-reducer-CiDEtmAq.js → selection-reducer-vKIb_jS6.js} +2 -2
  54. package/dist/chunks/{semaphor-ready-indicator-CHu1L-lo.js → semaphor-ready-indicator-CHHoWhil.js} +65586 -62749
  55. package/dist/chunks/{shelf-drop-preview-context-i-H6DFyU.js → shelf-drop-preview-context-EsayECEC.js} +199 -196
  56. package/dist/chunks/{source-entity-resolution-C-oNyYMp.js → source-entity-resolution-CVA1a85c.js} +8 -8
  57. package/dist/chunks/switch-CvItuC1Q.js +8199 -0
  58. package/dist/chunks/{temporal-bucket-DlFuhCnT.js → temporal-bucket-D8JF7zKz.js} +86 -71
  59. package/dist/chunks/{temporal-bucket-contract-D2OuaVZ7.js → temporal-bucket-contract-DaOajRC7.js} +1 -1
  60. package/dist/chunks/{token-types-DtSJOUjh.js → token-types-bxUxXDX2.js} +1 -1
  61. package/dist/chunks/{upload-CAIpsti1.js → upload-BFX7apKV.js} +1 -1
  62. package/dist/chunks/{use-create-flow-overlay-state-Bj63WwHc.js → use-create-flow-overlay-state-BqA92GkX.js} +331 -339
  63. package/dist/chunks/{validators-DMSH81OM.js → validators-Ej1DdCXa.js} +1050 -1510
  64. package/dist/chunks/visual-choice-JiJ-_3bi.js +204 -0
  65. package/dist/chunks/x-4f5U2XwU.js +100 -0
  66. package/dist/chunks/{zoned-wall-clock-1qlWCE20.js → zoned-wall-clock-MulfA26h.js} +2 -2
  67. package/dist/dashboard/index.js +2 -2
  68. package/dist/dashboard-authoring/index.js +823 -661
  69. package/dist/data-app-sdk/index.js +32 -30
  70. package/dist/data-app-sdk-adapters/index.js +23 -22
  71. package/dist/data-app-sdk-validation/index.js +23 -22
  72. package/dist/format-utils/index.js +173 -168
  73. package/dist/index.js +267 -258
  74. package/dist/layouts/index.js +236 -24
  75. package/dist/report-runtime-context/index.js +2 -2
  76. package/dist/style.css +1 -1
  77. package/dist/surfboard/index.js +2 -2
  78. package/dist/types/assistant-context.d.ts +2 -0
  79. package/dist/types/assistant-protocol.d.ts +2 -0
  80. package/dist/types/components/assistant/assistant-entry-points.d.ts +18 -0
  81. package/dist/types/components/assistant/assistant-provider.d.ts +19 -0
  82. package/dist/types/components/assistant/assistant-store.d.ts +52 -0
  83. package/dist/types/components/assistant/use-assistant.d.ts +38 -0
  84. package/dist/types/components/index.d.ts +5 -1
  85. package/dist/types/components/surfboard/filter/types.d.ts +5 -2
  86. package/dist/types/index.js +50 -51
  87. package/dist/types/lib/api/invalidate-token.d.ts +7 -0
  88. package/dist/types/lib/charts/cartesian-fields.d.ts +64 -0
  89. package/dist/types/lib/charts/types.d.ts +7 -0
  90. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-storage-transition.d.ts +14 -2
  91. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +5 -6
  92. package/dist/types/lib/dashboard-inputs/dashboard-input-values.d.ts +8 -3
  93. package/dist/types/lib/dashboard-inputs/resolve-dashboard-input-context.d.ts +11 -6
  94. package/dist/types/lib/dashboard-pagination/dashboard-card-pagination.d.ts +7 -0
  95. package/dist/types/lib/dashboard-viewer/compatibility-input-storage.d.ts +79 -0
  96. package/dist/types/lib/dashboard-viewer/viewer-state.d.ts +3 -2
  97. package/dist/types/lib/document/document-table-data-policy.d.ts +15 -0
  98. package/dist/types/lib/filter-values/filter-mode.d.ts +22 -0
  99. package/dist/types/lib/hooks/use-calendar-context.d.ts +5 -0
  100. package/dist/types/lib/hooks/use-text-filter.d.ts +7 -0
  101. package/dist/types/lib/print/print-inputs.d.ts +4 -2
  102. package/dist/types/lib/query-context/build-card-query-context.d.ts +12 -4
  103. package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +93 -0
  104. package/dist/types/lib/query-context/card-server-request.d.ts +72 -0
  105. package/dist/types/lib/query-context/compile-dashboard-card-filters.d.ts +7 -0
  106. package/dist/types/lib/query-context/describe-card-execution-snapshot.d.ts +56 -0
  107. package/dist/types/lib/query-context/document-section-card-query.d.ts +45 -0
  108. package/dist/types/lib/query-context/resolve-runtime-card-filters.d.ts +17 -2
  109. package/dist/types/lib/stores/dashboard-store.d.ts +34 -11
  110. package/dist/types/lib/stores/editor-store.d.ts +4 -2
  111. package/dist/types/lib/types/token-types.d.ts +11 -0
  112. package/dist/types/lib/utils/card-type-change.d.ts +30 -0
  113. package/dist/types/lib/utils/comparison-window-caption.d.ts +12 -0
  114. package/dist/types/lib/utils/filter-default-value-utils.d.ts +13 -2
  115. package/dist/types/shared/analytics-protocol/applied-constraints.d.ts +74 -0
  116. package/dist/types/shared/analytics-protocol/contracts.d.ts +3 -0
  117. package/dist/types/shared/analytics-protocol/filter-field-ownership.d.ts +43 -0
  118. package/dist/types/shared/analytics-protocol/index.d.ts +3 -0
  119. package/dist/types/shared/analytics-protocol/matrix-window-contract.d.ts +1 -1
  120. package/dist/types/shared/analytics-protocol/visual-choice.d.ts +75 -0
  121. package/dist/types/shared/assistant-context/index.d.ts +9 -0
  122. package/dist/types/shared/assistant-context/project-context.d.ts +55 -0
  123. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +130 -0
  124. package/dist/types/shared/assistant-protocol/add-to-dashboard.d.ts +17 -0
  125. package/dist/types/shared/assistant-protocol/artifact.d.ts +63 -0
  126. package/dist/types/shared/assistant-protocol/availability.d.ts +39 -0
  127. package/dist/types/shared/assistant-protocol/context.d.ts +952 -0
  128. package/dist/types/shared/assistant-protocol/conversation.d.ts +38 -0
  129. package/dist/types/shared/assistant-protocol/index.d.ts +16 -0
  130. package/dist/types/shared/assistant-protocol/limits.d.ts +53 -0
  131. package/dist/types/shared/assistant-protocol/parts.d.ts +131 -0
  132. package/dist/types/shared/assistant-protocol/request.d.ts +77 -0
  133. package/dist/types/shared/assistant-protocol/sources.d.ts +27 -0
  134. package/dist/types/shared/assistant-protocol/token-config.d.ts +32 -0
  135. package/dist/types/shared/assistant-protocol/transcript.d.ts +40 -0
  136. package/dist/types/shared/dashboard-authoring/card-query-request.d.ts +112 -0
  137. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +1794 -0
  138. package/dist/types/shared/dashboard-authoring/index.d.ts +5 -0
  139. package/dist/types/shared/dashboard-authoring/new-card.d.ts +10 -0
  140. package/dist/types/shared/dashboard-authoring/operations/apply-dashboard-operations.d.ts +40 -0
  141. package/dist/types/shared/dashboard-authoring/resolved-primary-date-field-validation.d.ts +16 -0
  142. package/dist/types/shared/format-utils/filter-detail.d.ts +70 -0
  143. package/dist/types/shared/format-utils/filter-value-text.d.ts +15 -0
  144. package/dist/types/shared/format-utils/index.d.ts +3 -0
  145. package/dist/types/shared/format-utils/raw-temporal.d.ts +7 -0
  146. package/dist/types/shared/format-utils/temporal-bucket.d.ts +7 -0
  147. package/dist/types/shared/layouts/frame-layouts.d.ts +23 -0
  148. package/dist/types/shared/layouts/index.d.ts +1 -0
  149. package/package.json +12 -2
  150. package/dist/chunks/calculated-field-identity-BptYhyOP.js +0 -1326
  151. package/dist/chunks/calendar-day-equality-BRjN1S9h.js +0 -383
  152. package/dist/chunks/card-config-utils-BOM1dxCk.js +0 -1150
  153. package/dist/chunks/constants-DNWVy8Y3.js +0 -9
  154. package/dist/chunks/dashboard-json-B1dEQu98.js +0 -65
  155. package/dist/chunks/field-aggregations-CoLzYHeL.js +0 -1229
  156. package/dist/chunks/index-DTcTAGGM.js +0 -4101
  157. package/dist/chunks/matrix-continuation-C4sRcjZU.js +0 -72
  158. package/dist/chunks/matrix-control-sources-DTqcA2_L.js +0 -636
  159. package/dist/chunks/matrix-definition-D9iShKZI.js +0 -87
  160. package/dist/chunks/matrix-member-presentation-Ct8GuxHt.js +0 -209
  161. package/dist/chunks/numeric-presentation-CWu3gunq.js +0 -537
  162. package/dist/chunks/pivot-header-presentation-CHs2GFrM.js +0 -753
  163. package/dist/chunks/pivot-result-lifecycle-DQz_gjGu.js +0 -789
  164. package/dist/chunks/raw-temporal-iMXRK-Qz.js +0 -930
  165. package/dist/chunks/report-preferences-dialog-DXPjteCU.js +0 -1623
  166. package/dist/chunks/save-kO6cIaob.js +0 -34
  167. package/dist/chunks/semantic-format-DiqYeKwU.js +0 -192
  168. package/dist/chunks/switch-DO8a0EfJ.js +0 -25004
  169. package/dist/chunks/temporal-input-presentation-BD7YNUzu.js +0 -195
  170. package/dist/chunks/x-CXDkqdur.js +0 -149
  171. package/dist/types/lib/class-utils.d.ts +0 -2
  172. package/dist/types/lib/document/document-input-runtime.d.ts +0 -26
  173. package/dist/types/lib/utils.d.ts +0 -51
@@ -0,0 +1,3164 @@
1
+ var Ke = Object.defineProperty;
2
+ var qe = (e, n, t) => n in e ? Ke(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
+ var K = (e, n, t) => qe(e, typeof n != "symbol" ? n + "" : n, t);
4
+ import { z as H, q as z, t as Ue, R as Ve, y as je, m as ye, g as He } from "./raw-temporal-D61lr48Y.js";
5
+ import { a9 as oe, l as Ge, t as We } from "./validators-Ej1DdCXa.js";
6
+ import { C as Ze } from "./csv-utils-GUfKyT1J.js";
7
+ import { n as Qe, q as Xe, i as Ye, l as Je, P as L } from "./pivot-result-lifecycle-8qCDmpKc.js";
8
+ import { af as et, ah as tt, V as nt } from "./matrix-operation-contract-B8PBF1Gd.js";
9
+ import "./analytics-base-schemas-BFAoRlkU.js";
10
+ import { z as g } from "zod";
11
+ import { DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as rt } from "../value-format-preferences/index.js";
12
+ import { r as ot } from "./matrix-definition-DQDI2okF.js";
13
+ import { a as at, r as G, n as ae, b as it, c as ct, f as lt, d as dt, e as st, h as mt } from "./custom-visual-inputs-BrUOIwln.js";
14
+ import { r as ut } from "./matrix-card-CJn1hB5V.js";
15
+ import { j as ft } from "./common-types-CUf03Htv.js";
16
+ import { r as pt } from "./pivot-result-identity-D6hhcRXi.js";
17
+ import { v as ge } from "./raw-temporal-contract-C51YG48G.js";
18
+ import "./calculated-field-identity-DcBS2NPP.js";
19
+ import { r as ht, a as yt, b as gt } from "./canonical-result-keys-CEQefvdO.js";
20
+ const vt = /* @__PURE__ */ new Set([
21
+ "table",
22
+ "aggregateTable",
23
+ "pivotTable",
24
+ "detailTable"
25
+ ]), bt = /* @__PURE__ */ new Set([
26
+ "bar",
27
+ "horizontalBar",
28
+ "line",
29
+ "area",
30
+ "stackedArea",
31
+ "combo",
32
+ "pie",
33
+ "doughnut",
34
+ "radar",
35
+ "polarArea",
36
+ "bubble",
37
+ "scatter",
38
+ "stackedBar",
39
+ "stackedLine",
40
+ "table",
41
+ "pivotTable",
42
+ "aggregateTable",
43
+ "matrixTable",
44
+ "detailTable",
45
+ "kpi",
46
+ "pyramid",
47
+ "tornado",
48
+ "range",
49
+ "map",
50
+ "funnel",
51
+ "bullet",
52
+ "heatmap",
53
+ "treemap",
54
+ "custom"
55
+ ]);
56
+ function ar(e) {
57
+ var o, a, i;
58
+ const n = bt.has(e.type) && (e.type !== "custom" || !!((o = e.customCardPreferences) != null && o.url));
59
+ let t = !1;
60
+ try {
61
+ t = !!ut(e);
62
+ } catch {
63
+ return { formats: [], defaultFormat: null };
64
+ }
65
+ return e.type === "text" || !n || !t && at(e) ? { formats: [], defaultFormat: null } : {
66
+ formats: It({
67
+ cardType: e.type,
68
+ allowDownload: (a = e.preferences) == null ? void 0 : a.allowDownload
69
+ }),
70
+ defaultFormat: wt({
71
+ cardType: e.type,
72
+ allowDownload: (i = e.preferences) == null ? void 0 : i.allowDownload
73
+ })
74
+ };
75
+ }
76
+ function It(e) {
77
+ return e.allowDownload === !1 ? ["pdf"] : ["pdf", "csv"];
78
+ }
79
+ function wt(e) {
80
+ return vt.has(e.cardType) && e.allowDownload !== !1 ? "csv" : "pdf";
81
+ }
82
+ function ir(e) {
83
+ const { config: n } = e, t = ot({
84
+ spec: n.spec,
85
+ presentation: n.presentation,
86
+ defaults: n.defaultView,
87
+ session: e.purpose === "manual" ? e.session : void 0
88
+ });
89
+ return oe.parse({
90
+ spec: t.spec,
91
+ presentation: t.presentation,
92
+ ...e.content === "flat" ? { mode: "flat", format: "csv" } : {
93
+ mode: "layout",
94
+ format: e.format,
95
+ expansion: e.content === "all" ? { kind: "all" } : {
96
+ kind: "current",
97
+ rows: t.view.rows,
98
+ columns: t.view.columns
99
+ }
100
+ }
101
+ });
102
+ }
103
+ const $t = g.object({
104
+ connection_id: g.string().min(1),
105
+ cardType: g.literal("matrixTable"),
106
+ resultOwner: g.literal("config"),
107
+ sql: g.literal("").optional(),
108
+ python: g.literal("").optional(),
109
+ tableStructure: g.never().optional(),
110
+ cardDataSource: g.object({
111
+ connectionId: g.string().min(1),
112
+ connectionType: g.string().min(1),
113
+ mode: g.enum(["database", "semanticDomain"]),
114
+ selectedEntities: g.array(g.unknown()),
115
+ semanticDomainId: g.string().optional()
116
+ }).passthrough(),
117
+ active_filters: g.array(g.unknown()).default([])
118
+ }).passthrough(), cr = $t.extend({
119
+ dashboardId: g.string().min(1),
120
+ cardId: g.string().min(1),
121
+ formatOptions: g.object({
122
+ matrix: oe,
123
+ acquisition: g.literal("continuation").optional(),
124
+ presentationExecutionSnapshot: g.unknown()
125
+ }).passthrough().superRefine((e, n) => {
126
+ e.matrix.format === "csv" != (e.acquisition === "continuation") && n.addIssue({
127
+ code: g.ZodIssueCode.custom,
128
+ path: ["acquisition"],
129
+ message: "CSV requires continuation acquisition; PDF must not specify acquisition."
130
+ });
131
+ })
132
+ });
133
+ function lr(e) {
134
+ return {
135
+ ...e.controls,
136
+ type: "card",
137
+ dashboardId: e.dashboardId,
138
+ cardId: e.cardId,
139
+ title: e.title,
140
+ cardType: "matrixTable",
141
+ resultOwner: "config",
142
+ sql: "",
143
+ python: "",
144
+ connection_id: e.dataSource.connectionId,
145
+ // Editor metadata can omit mode; the captured source owns dataset identity.
146
+ cardDataSource: {
147
+ ...e.dataSource,
148
+ mode: e.matrix.spec.source.kind === "semantic" ? "semanticDomain" : "database",
149
+ semanticDomainId: e.matrix.spec.source.kind === "semantic" ? e.matrix.spec.source.domainId : void 0
150
+ },
151
+ active_filters: e.activeFilters,
152
+ formatOptions: {
153
+ ...e.matrix.format === "csv" ? {
154
+ acquisition: "continuation",
155
+ ...e.csvEncoding ? { csvEncoding: e.csvEncoding } : {}
156
+ } : {},
157
+ matrix: e.matrix,
158
+ delimiter: e.delimiter,
159
+ includeHeaders: e.includeHeaders,
160
+ timezone: e.reportContext.calendar.tz,
161
+ presentationExecutionSnapshot: Qe({
162
+ reportContext: e.reportContext,
163
+ resolvedFormats: []
164
+ })
165
+ }
166
+ };
167
+ }
168
+ const Q = g.number().int().nonnegative(), dr = g.discriminatedUnion("status", [
169
+ g.object({
170
+ status: g.literal("ok"),
171
+ request: oe,
172
+ layout: et,
173
+ rows: g.array(tt).readonly(),
174
+ usage: g.object({ rows: Q, cells: Q, bytes: Q }).strict()
175
+ }).strict(),
176
+ g.object({
177
+ status: g.literal("failed"),
178
+ failure: g.object({
179
+ code: g.enum(nt),
180
+ limit: g.enum(["rows", "bytes"]).optional(),
181
+ message: g.string().min(1),
182
+ retryable: g.boolean()
183
+ }).strict()
184
+ }).strict()
185
+ ]);
186
+ function ue(e) {
187
+ return !e || typeof e != "object" ? !1 : Array.isArray(e.cards);
188
+ }
189
+ function Ct(e) {
190
+ if (!e)
191
+ return null;
192
+ if (typeof e == "string")
193
+ try {
194
+ const n = JSON.parse(e);
195
+ return ue(n) ? n : null;
196
+ } catch {
197
+ return null;
198
+ }
199
+ return ue(e) ? e : null;
200
+ }
201
+ function ve(e) {
202
+ var n;
203
+ return (n = e == null ? void 0 : e.cards) != null && n.length ? e.activeCardId && e.cards.find((t) => t.id === e.activeCardId) || e.cards[0] : null;
204
+ }
205
+ function sr(e) {
206
+ var t;
207
+ const n = (e == null ? void 0 : e.frameObject) ?? ((t = e == null ? void 0 : e.visual) == null ? void 0 : t.frameObject);
208
+ return ve(Ct(n));
209
+ }
210
+ class T extends Error {
211
+ constructor(n, t, r) {
212
+ super(`${n}: ${t}`), this.code = n, this.context = r, Object.setPrototypeOf(this, T.prototype), this.name = "RawTemporalPresentationBoundaryError";
213
+ }
214
+ }
215
+ function be() {
216
+ return { type: "raw_temporal", presentation: { mode: "auto" } };
217
+ }
218
+ function Tt(e) {
219
+ if (e.locale || e.relative || e.timezone && e.timezone !== "auto" || e.sourceTimezone && e.sourceTimezone !== "auto" || e.prefix || e.suffix)
220
+ throw new T(
221
+ "invalid_raw_temporal_format",
222
+ "Activated raw temporal presentation contains unsupported locale, relative-time, timezone, prefix, or suffix settings."
223
+ );
224
+ }
225
+ function Ie(e) {
226
+ const n = e.format;
227
+ if ((n == null ? void 0 : n.type) === "date" && (Tt(n), n.pattern))
228
+ return {
229
+ type: "raw_temporal",
230
+ presentation: {
231
+ mode: "pattern",
232
+ dialect: "semaphor_tokens",
233
+ pattern: n.pattern
234
+ }
235
+ };
236
+ if (n)
237
+ throw new T(
238
+ "invalid_raw_temporal_format",
239
+ `Raw temporal detail field "${e.id}" has an incompatible authored format.`,
240
+ { fieldId: e.id }
241
+ );
242
+ if (e.dateFormat === "custom") {
243
+ if (!e.customFormat)
244
+ throw new T(
245
+ "invalid_raw_temporal_format",
246
+ `Raw temporal detail field "${e.id}" selects a custom pattern but has no customFormat.`,
247
+ { fieldId: e.id }
248
+ );
249
+ return {
250
+ type: "raw_temporal",
251
+ presentation: {
252
+ mode: "pattern",
253
+ dialect: "semaphor_tokens",
254
+ pattern: e.customFormat
255
+ }
256
+ };
257
+ }
258
+ return e.dateFormat ? {
259
+ type: "raw_temporal",
260
+ presentation: {
261
+ mode: "pattern",
262
+ dialect: "semaphor_tokens",
263
+ pattern: e.dateFormat
264
+ }
265
+ } : be();
266
+ }
267
+ function ie(e) {
268
+ var i;
269
+ if (e != null && e.useRelativeTime) return;
270
+ if (!e) return be();
271
+ if (e.useCustomFormat && !((i = e.customFormat) != null && i.trim()))
272
+ throw new T(
273
+ "invalid_raw_temporal_format",
274
+ "Declared SQL temporal presentation selects a custom pattern but has no customFormat.",
275
+ { reason: "missing_declared_sql_custom_date_format" }
276
+ );
277
+ const n = e.useCustomFormat && e.customFormat ? e.customFormat : e.format, t = e.timezone, r = e.sourceTimezone, o = t && t !== "auto" ? { timezone: t } : void 0, a = {
278
+ sourceTimezone: r && r !== "auto" ? r : "UTC"
279
+ };
280
+ return n ? {
281
+ type: "raw_temporal",
282
+ ...o,
283
+ ...a,
284
+ presentation: {
285
+ mode: "pattern",
286
+ dialect: "date_fns",
287
+ pattern: n
288
+ }
289
+ } : {
290
+ type: "raw_temporal",
291
+ ...o,
292
+ ...a,
293
+ presentation: { mode: "auto" }
294
+ };
295
+ }
296
+ function mr(e) {
297
+ return e === "instant" ? "yyyy-MM-dd'T'HH:mm:ssXXX" : e === "wall_datetime" ? "yyyy-MM-dd'T'HH:mm:ss" : "yyyy-MM-dd";
298
+ }
299
+ function ur(e) {
300
+ je({
301
+ dialect: "date_fns",
302
+ pattern: e.pattern,
303
+ valueKind: e.valueKind
304
+ });
305
+ }
306
+ function Et(e) {
307
+ const n = ie(e.settings);
308
+ if (!n)
309
+ throw new T(
310
+ "invalid_raw_temporal_format",
311
+ "Relative-time SQL presentation does not have an absolute date preview."
312
+ );
313
+ const t = e.valueKind ?? (n.presentation.mode === "pattern" ? "instant" : "date"), r = {
314
+ kind: "raw_temporal",
315
+ valueKind: t
316
+ }, o = e.value ?? (t === "date" ? "2023-05-15" : t === "wall_datetime" ? "2023-05-15T14:30:45" : "2023-05-15T14:30:45Z"), a = H({
317
+ metadata: r,
318
+ format: z({
319
+ format: n,
320
+ preferences: e.preferences,
321
+ calendar: { tz: e.calendarTimezone }
322
+ })
323
+ })(o);
324
+ if (!a.ok)
325
+ throw new T(
326
+ "invalid_raw_temporal_format",
327
+ a.diagnostic.message
328
+ );
329
+ return a.text;
330
+ }
331
+ function fr(e) {
332
+ try {
333
+ return { ok: !0, text: Et(e) };
334
+ } catch (n) {
335
+ return {
336
+ ok: !1,
337
+ message: n instanceof Error ? n.message : "Invalid SQL temporal presentation."
338
+ };
339
+ }
340
+ }
341
+ function we(e) {
342
+ var t;
343
+ const n = e.effectiveCardConfig ?? e.card.config;
344
+ return G(e.card, n) === "freeform" && !!((t = e.card.sql) != null && t.trim()) && !ae(e.card.python || "").trim();
345
+ }
346
+ function xt(e) {
347
+ var n, t;
348
+ return e.type !== "table" && e.type !== "detailTable" || !we({ card: e }) ? !1 : Object.values(
349
+ ((t = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : t.columnSettingsMap) || {}
350
+ ).some(
351
+ (r) => {
352
+ var o, a, i;
353
+ return r.type === "date" && ((o = r.dateFormat) == null ? void 0 : o.useRelativeTime) !== !0 && ((a = r.dateFormat) == null ? void 0 : a.useCustomFormat) === !0 && !((i = r.dateFormat.customFormat) != null && i.trim());
354
+ }
355
+ );
356
+ }
357
+ function pr(e) {
358
+ var t, r, o;
359
+ if (!xt(e)) return e;
360
+ const n = ((r = (t = e.preferences) == null ? void 0 : t.tablePrefs) == null ? void 0 : r.columnSettingsMap) || {};
361
+ return {
362
+ ...e,
363
+ preferences: {
364
+ ...e.preferences,
365
+ tablePrefs: {
366
+ ...(o = e.preferences) == null ? void 0 : o.tablePrefs,
367
+ columnSettingsMap: Object.fromEntries(
368
+ Object.entries(n).map(([a, i]) => {
369
+ var c, l, d;
370
+ return [
371
+ a,
372
+ i.type === "date" && ((c = i.dateFormat) == null ? void 0 : c.useRelativeTime) !== !0 && ((l = i.dateFormat) == null ? void 0 : l.useCustomFormat) === !0 && !((d = i.dateFormat.customFormat) != null && d.trim()) ? {
373
+ ...i,
374
+ dateFormat: {
375
+ ...i.dateFormat,
376
+ format: "",
377
+ useCustomFormat: !1,
378
+ customFormat: ""
379
+ }
380
+ } : i
381
+ ];
382
+ })
383
+ )
384
+ }
385
+ }
386
+ };
387
+ }
388
+ function St() {
389
+ return {
390
+ activatedColumnKeys: /* @__PURE__ */ new Set(),
391
+ byColumnKey: /* @__PURE__ */ new Map(),
392
+ byFieldId: /* @__PURE__ */ new Map()
393
+ };
394
+ }
395
+ function te(e, n) {
396
+ return e === void 0 ? { kind: "invalid", error: n } : {
397
+ kind: "invalid",
398
+ error: e instanceof T ? e : e instanceof Ve ? new T(
399
+ e.code,
400
+ e.message,
401
+ n.context
402
+ ) : new T(
403
+ n.code,
404
+ e instanceof Error ? e.message : n.message,
405
+ n.context
406
+ )
407
+ };
408
+ }
409
+ function kt(e) {
410
+ var o;
411
+ if (e.cardType !== "detailTable" || e.resultOwner !== "config")
412
+ return { kind: "inactive" };
413
+ if (!e.result) return { kind: "loading" };
414
+ const { records: n, columns: t, columnKeyMap: r } = e.result;
415
+ if (!Array.isArray(n) || !Array.isArray(t) || !r)
416
+ return te(
417
+ void 0,
418
+ new T(
419
+ "missing_raw_temporal_result_contract",
420
+ "Activated raw temporal detail results require records, columns, and columnKeyMap atomically."
421
+ )
422
+ );
423
+ try {
424
+ const a = t.filter((m) => m.rawTemporal);
425
+ if (a.length === 0) return { kind: "inactive" };
426
+ const i = new Map(
427
+ (((o = e.effectiveCardConfig) == null ? void 0 : o.detailColumns) || []).map((m) => [
428
+ m.id,
429
+ m
430
+ ])
431
+ ), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
432
+ for (const m of a) {
433
+ const p = Array.from(i).flatMap(
434
+ ([E, Z]) => {
435
+ const O = pt(
436
+ r,
437
+ E,
438
+ "detail"
439
+ );
440
+ return O && O.role === "detail" && (O.outputKey ?? O.rawKey) === m.key ? [{ field: Z, binding: O }] : [];
441
+ }
442
+ ), f = p.length === 1 ? p[0] : null;
443
+ if (!f || typeof f.binding.rawKey != "string" || f.binding.rawKey.trim().length === 0 || f.binding.outputKey !== void 0 && (typeof f.binding.outputKey != "string" || f.binding.outputKey.trim().length === 0))
444
+ throw new T(
445
+ "missing_raw_temporal_column_binding",
446
+ `Raw temporal result column "${m.key}" does not have one valid exact detail result binding.`,
447
+ { columnKey: m.key }
448
+ );
449
+ const { field: h, binding: I } = f, w = I.outputKey ?? I.rawKey, x = ge(m, {
450
+ metadataRequired: !0
451
+ });
452
+ if (!x)
453
+ throw new T(
454
+ "invalid_raw_temporal_metadata",
455
+ `Raw temporal result column "${w}" has no metadata.`,
456
+ { fieldId: h.id, columnKey: w }
457
+ );
458
+ const k = z({
459
+ format: Ie(h),
460
+ preferences: e.preferences,
461
+ calendar: e.calendar
462
+ }), C = {
463
+ fieldId: h.id,
464
+ columnKey: w,
465
+ metadata: x,
466
+ format: k,
467
+ formatValue: H({ metadata: x, format: k })
468
+ };
469
+ for (let E = 0; E < n.length; E += 1)
470
+ if (!Object.prototype.hasOwnProperty.call(n[E], w) || n[E][w] === void 0)
471
+ throw new T(
472
+ "missing_raw_temporal_result_contract",
473
+ `Raw temporal result row ${E} is missing column "${w}".`,
474
+ { fieldId: h.id, columnKey: w }
475
+ );
476
+ c.set(w, C), l.set(h.id, C);
477
+ }
478
+ const d = {
479
+ activatedColumnKeys: new Set(c.keys()),
480
+ byColumnKey: c,
481
+ byFieldId: l
482
+ };
483
+ return n.length === 0 ? { kind: "loaded_empty", presentation: d } : { kind: "loaded_valid", presentation: d };
484
+ } catch (a) {
485
+ return te(
486
+ a,
487
+ new T(
488
+ "invalid_raw_temporal_metadata",
489
+ "Activated raw temporal result metadata is invalid."
490
+ )
491
+ );
492
+ }
493
+ }
494
+ function _t(e) {
495
+ var r, o, a;
496
+ const n = e.effectiveCardConfig ?? e.card.config, t = G(
497
+ e.card,
498
+ n
499
+ );
500
+ if (e.card.type === "detailTable" && t === "config") {
501
+ const i = !!((r = e.columns) != null && r.some((c) => c.rawTemporal));
502
+ return i && e.records !== void 0 && !e.columnKeyMap ? {
503
+ kind: "invalid",
504
+ error: new T(
505
+ "missing_raw_temporal_result_contract",
506
+ "Activated raw temporal detail results require records, columns, and columnKeyMap atomically."
507
+ )
508
+ } : e.records !== void 0 && !i ? { kind: "inactive" } : fe(
509
+ kt({
510
+ cardType: e.card.type,
511
+ resultOwner: t,
512
+ effectiveCardConfig: n,
513
+ result: e.records === void 0 || !e.columns || !e.columnKeyMap ? void 0 : {
514
+ records: e.records,
515
+ columns: e.columns,
516
+ columnKeyMap: e.columnKeyMap
517
+ },
518
+ preferences: e.preferences,
519
+ calendar: e.calendar
520
+ }),
521
+ e
522
+ );
523
+ }
524
+ return fe(
525
+ At({
526
+ resultOwner: t,
527
+ sql: e.card.sql,
528
+ normalizedPython: ae(
529
+ e.card.python || ""
530
+ ),
531
+ records: e.records,
532
+ columns: e.columns,
533
+ columnSettings: (a = (o = e.card.preferences) == null ? void 0 : o.tablePrefs) == null ? void 0 : a.columnSettingsMap,
534
+ preferences: e.preferences,
535
+ calendar: e.calendar
536
+ }),
537
+ e
538
+ );
539
+ }
540
+ function hr(e) {
541
+ var r, o, a;
542
+ const n = e.effectiveCardConfig ?? e.card.config, t = G(
543
+ e.card,
544
+ n
545
+ );
546
+ return e.card.type === "detailTable" && t === "config" ? !!((r = e.columns) != null && r.some((i) => i.rawTemporal)) : we(e) ? Object.values(
547
+ ((a = (o = e.card.preferences) == null ? void 0 : o.tablePrefs) == null ? void 0 : a.columnSettingsMap) || {}
548
+ ).some(
549
+ (i) => {
550
+ var c;
551
+ return i.type === "date" && !((c = i.dateFormat) != null && c.useRelativeTime);
552
+ }
553
+ ) : !1;
554
+ }
555
+ function fe(e, n) {
556
+ if (!n.executionSnapshot || e.kind === "inactive" || e.kind === "loading" || e.kind === "invalid")
557
+ return e;
558
+ if (!n.dashboardId)
559
+ return {
560
+ kind: "invalid",
561
+ error: new T(
562
+ "missing_raw_temporal_result_contract",
563
+ "A dashboard ID is required to resolve the captured raw temporal presentation."
564
+ )
565
+ };
566
+ const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
567
+ for (const o of e.presentation.activatedColumnKeys) {
568
+ const a = Xe({
569
+ snapshot: n.executionSnapshot,
570
+ scope: {
571
+ dashboardId: n.dashboardId,
572
+ cardId: n.card.id,
573
+ ...n.attachmentIndex !== void 0 ? { attachmentIndex: n.attachmentIndex } : {}
574
+ },
575
+ target: { kind: "column", columnKey: o }
576
+ });
577
+ if (!a)
578
+ return {
579
+ kind: "invalid",
580
+ error: new Ye(o)
581
+ };
582
+ const i = e.presentation.byColumnKey.get(o);
583
+ if (!i) continue;
584
+ const c = {
585
+ ...i,
586
+ format: a,
587
+ formatValue: H({
588
+ metadata: i.metadata,
589
+ format: a
590
+ })
591
+ };
592
+ t.set(i.columnKey, c), i.fieldId && r.set(i.fieldId, c);
593
+ }
594
+ return {
595
+ ...e,
596
+ presentation: {
597
+ activatedColumnKeys: e.presentation.activatedColumnKeys,
598
+ byColumnKey: t,
599
+ byFieldId: r
600
+ }
601
+ };
602
+ }
603
+ function At(e) {
604
+ var t, r;
605
+ if (e.resultOwner !== "freeform" || !((t = e.sql) != null && t.trim()) || (r = e.normalizedPython) != null && r.trim())
606
+ return { kind: "inactive" };
607
+ const n = Object.entries(
608
+ e.columnSettings || {}
609
+ ).filter(
610
+ ([, o]) => {
611
+ var a;
612
+ return o.type === "date" && !((a = o.dateFormat) != null && a.useRelativeTime);
613
+ }
614
+ );
615
+ if (n.length === 0) return { kind: "inactive" };
616
+ if (!e.records) return { kind: "loading" };
617
+ try {
618
+ const o = /* @__PURE__ */ new Map(), a = new Set(
619
+ n.map(([d]) => d)
620
+ ), i = /* @__PURE__ */ new Map(), c = [...e.columns || []];
621
+ for (const [d, m] of n) {
622
+ const p = ie(
623
+ m.dateFormat
624
+ );
625
+ if (!p) continue;
626
+ const f = Ue({
627
+ columnKey: d,
628
+ values: e.records.map((x) => {
629
+ if (!Object.prototype.hasOwnProperty.call(x, d))
630
+ throw new T(
631
+ "missing_raw_temporal_result_contract",
632
+ `Declared SQL temporal column "${d}" is absent from a physical result row.`,
633
+ { columnKey: d }
634
+ );
635
+ const k = x[d];
636
+ return k === null || typeof k == "string" ? k : String(k);
637
+ })
638
+ });
639
+ if (i.set(d, f), f.status !== "classified") continue;
640
+ let h = c.findIndex(
641
+ (x) => x.key === d
642
+ );
643
+ if (e.columns && h < 0)
644
+ throw new T(
645
+ "missing_raw_temporal_result_contract",
646
+ `Classified SQL temporal column "${d}" is absent from result columns.`,
647
+ { columnKey: d }
648
+ );
649
+ h < 0 && (h = c.length, c.push({
650
+ key: d,
651
+ name: d,
652
+ label: d,
653
+ role: "dimension",
654
+ dataType: "string"
655
+ }));
656
+ const I = {
657
+ ...c[h],
658
+ role: "date",
659
+ dataType: f.metadata.valueKind === "date" ? "date" : "datetime",
660
+ rawTemporal: f.metadata
661
+ };
662
+ ge(I, {
663
+ metadataRequired: !0
664
+ }), c[h] = I;
665
+ const w = z({
666
+ format: p,
667
+ preferences: e.preferences,
668
+ calendar: e.calendar
669
+ });
670
+ o.set(d, {
671
+ columnKey: d,
672
+ metadata: f.metadata,
673
+ format: w,
674
+ formatValue: H({
675
+ metadata: f.metadata,
676
+ format: w
677
+ })
678
+ });
679
+ }
680
+ const l = {
681
+ ...St(),
682
+ activatedColumnKeys: a,
683
+ byColumnKey: o
684
+ };
685
+ return e.records.length === 0 ? {
686
+ kind: "loaded_empty",
687
+ presentation: l,
688
+ adaptedColumns: c,
689
+ sqlClassifications: i
690
+ } : {
691
+ kind: "loaded_valid",
692
+ presentation: l,
693
+ adaptedColumns: c,
694
+ sqlClassifications: i
695
+ };
696
+ } catch (o) {
697
+ return te(
698
+ o,
699
+ new T(
700
+ "invalid_raw_temporal_format",
701
+ "Declared SQL raw temporal presentation is invalid."
702
+ )
703
+ );
704
+ }
705
+ }
706
+ function yr(e) {
707
+ if (e.value !== null && typeof e.value != "string")
708
+ return {
709
+ value: e.value,
710
+ label: String(e.value),
711
+ result: {
712
+ ok: !1,
713
+ text: String(e.value),
714
+ diagnostic: {
715
+ code: "invalid_raw_temporal_value",
716
+ message: `Raw temporal column "${e.presentation.columnKey}" must contain a string or null.`
717
+ }
718
+ }
719
+ };
720
+ const n = e.presentation.formatValue(e.value);
721
+ return { value: e.value, label: n.text, result: n };
722
+ }
723
+ function gr(e) {
724
+ if (!e.result || typeof e.result != "object") return !1;
725
+ const n = e.result;
726
+ if (e.expectedResultOwner !== void 0 && n.resultOwner !== e.expectedResultOwner || !Array.isArray(n.records)) return !1;
727
+ const t = _t({
728
+ card: e.card,
729
+ effectiveCardConfig: e.effectiveCardConfig,
730
+ records: n.records,
731
+ columns: n.columns,
732
+ columnKeyMap: n.columnKeyMap,
733
+ preferences: rt,
734
+ calendar: { tz: "UTC" }
735
+ });
736
+ return t.kind === "inactive" || t.kind === "loaded_empty" || t.kind === "loaded_valid";
737
+ }
738
+ class q extends Error {
739
+ constructor(t) {
740
+ const r = t.cardId ? `card "${t.cardId}"` : t.sheetId ? `sheet "${t.sheetId}"` : `dashboard "${t.dashboardId}"`;
741
+ super(
742
+ `Unable to resolve ${r} while capturing report presentation. Refresh the authoring page and select the attachment again.`
743
+ );
744
+ K(this, "code", "temporal_snapshot_target_not_found");
745
+ K(this, "selection");
746
+ this.name = "TemporalSnapshotSelectionError", this.selection = t;
747
+ }
748
+ }
749
+ function Ft(e, n) {
750
+ var o;
751
+ const t = [], r = /* @__PURE__ */ new Map();
752
+ for (const a of n) {
753
+ if (a.dashboardId !== e.id)
754
+ throw new q(a);
755
+ const i = (e.sheets || []).filter(
756
+ (l) => !a.sheetId || a.sheetId === l.id
757
+ );
758
+ if (a.sheetId && i.length === 0)
759
+ throw new q(a);
760
+ let c = !a.cardId;
761
+ for (const l of i) {
762
+ const d = (((o = l.document) == null ? void 0 : o.sections) || []).flatMap(
763
+ (f) => ft(f)
764
+ ), m = (l.frames || []).flatMap(
765
+ (f) => Dt(f, a.cardId)
766
+ );
767
+ m.length > 0 && (c = !0);
768
+ const p = [
769
+ ...m,
770
+ ...(l.cards || []).filter(
771
+ (f) => !a.cardId || a.cardId === f.id
772
+ ),
773
+ ...d.filter(
774
+ (f) => !a.cardId || a.cardId === f.id
775
+ )
776
+ ];
777
+ for (const f of p) {
778
+ c = !0;
779
+ const h = r.get(a.attachmentIndex) ?? /* @__PURE__ */ new Set();
780
+ h.has(f.id) || (h.add(f.id), r.set(a.attachmentIndex, h), t.push({
781
+ card: f,
782
+ ...a.attachmentIndex !== void 0 ? { attachmentIndex: a.attachmentIndex } : {}
783
+ }));
784
+ }
785
+ }
786
+ if (!c)
787
+ throw new q(a);
788
+ }
789
+ return t;
790
+ }
791
+ function Dt(e, n) {
792
+ var i;
793
+ const t = n ? (i = e.cards) == null ? void 0 : i.find((c) => c.id === n) : ve(e);
794
+ if (!t) return [];
795
+ const r = lt(e, t), o = (e.cards || []).filter(
796
+ (c) => {
797
+ var l;
798
+ return typeof ((l = c.customCardPreferences) == null ? void 0 : l.slotIndex) == "number";
799
+ }
800
+ ).length > 1, a = r != null && (dt(r) === "multiple" || o);
801
+ return !r || !a ? [t] : st(
802
+ mt({
803
+ frame: e,
804
+ configCard: r,
805
+ isMultiInputVisual: !0
806
+ })
807
+ ).filter((c) => c !== null);
808
+ }
809
+ function vr(e) {
810
+ return Ft(e.dashboard, e.selections).flatMap(
811
+ ({ card: n, attachmentIndex: t }) => {
812
+ var m, p, f, h;
813
+ const r = ((m = e.resolveCardConfig) == null ? void 0 : m.call(e, n)) ?? n.config, o = it({
814
+ card: n,
815
+ cardConfig: r
816
+ }), a = {
817
+ dashboardId: e.dashboard.id,
818
+ cardId: n.id,
819
+ ...t !== void 0 ? { attachmentIndex: t } : {}
820
+ }, i = o ? o.fields.map((I) => ({
821
+ scope: a,
822
+ target: {
823
+ kind: "field",
824
+ fieldId: I.id,
825
+ role: I.role
826
+ },
827
+ format: ct(
828
+ I,
829
+ {
830
+ dateStyle: e.valueFormatPreferences.dateStyle,
831
+ dateTime: { ...e.valueFormatPreferences.dateTime }
832
+ },
833
+ e.valueFormatPreferences.locale
834
+ )
835
+ })) : [], c = [], l = G(n, r), d = ae(
836
+ n.python || ""
837
+ );
838
+ if (n.type === "detailTable" && l === "config") {
839
+ const I = (r == null ? void 0 : r.detailColumns) || [], w = [
840
+ ...((r == null ? void 0 : r.groupByColumns) || []).map((C) => ({
841
+ field: C,
842
+ role: "groupby"
843
+ })),
844
+ ...((r == null ? void 0 : r.metricColumns) || []).map((C) => ({
845
+ field: C,
846
+ role: "metric"
847
+ })),
848
+ ...((r == null ? void 0 : r.pivotByColumns) || []).map((C) => ({
849
+ field: C,
850
+ role: "pivotby"
851
+ })),
852
+ ...I.map((C) => ({
853
+ field: C,
854
+ role: "detail"
855
+ }))
856
+ ], x = /* @__PURE__ */ new Map(), k = new Set(
857
+ w.map(
858
+ ({ field: C, role: E }) => ht(C, E)
859
+ )
860
+ );
861
+ for (const { field: C } of w) {
862
+ const E = C.label;
863
+ E && x.set(E, (x.get(E) || 0) + 1);
864
+ }
865
+ for (const C of I) {
866
+ const E = Ge(C.dataType);
867
+ if (E !== "date" && E !== "datetime") continue;
868
+ const Z = yt(C), O = C.label, me = gt({
869
+ label: O,
870
+ labelCount: O && x.get(O) || 0,
871
+ rawKey: Z,
872
+ rawKeys: k
873
+ });
874
+ if (!me) throw new q(a);
875
+ c.push({
876
+ scope: a,
877
+ target: { kind: "column", columnKey: me },
878
+ format: z({
879
+ format: Ie(C),
880
+ preferences: e.valueFormatPreferences,
881
+ calendar: e.calendar
882
+ })
883
+ });
884
+ }
885
+ } else if (l === "freeform" && ((p = n.sql) != null && p.trim()) && !d.trim())
886
+ for (const [I, w] of Object.entries(
887
+ ((h = (f = n.preferences) == null ? void 0 : f.tablePrefs) == null ? void 0 : h.columnSettingsMap) || {}
888
+ )) {
889
+ if (w.type !== "date") continue;
890
+ const x = ie(
891
+ w.dateFormat
892
+ );
893
+ x && c.push({
894
+ scope: a,
895
+ target: { kind: "column", columnKey: I },
896
+ format: z({
897
+ format: x,
898
+ preferences: e.valueFormatPreferences,
899
+ calendar: e.calendar
900
+ })
901
+ });
902
+ }
903
+ return [...i, ...c];
904
+ }
905
+ );
906
+ }
907
+ function Rt(e) {
908
+ return !!e && typeof e == "object" && !Array.isArray(e);
909
+ }
910
+ function F(e, n, t) {
911
+ return Rt(e) ? e : (t.push({ field: n, message: "Expected an object." }), {});
912
+ }
913
+ function D(e, n, t, r) {
914
+ const o = new Set(t);
915
+ Object.keys(e).forEach((a) => {
916
+ o.has(a) || r.push({
917
+ field: `${n}.${a}`,
918
+ message: "Unexpected property."
919
+ });
920
+ });
921
+ }
922
+ function B(e, n, t, r, o = {}) {
923
+ if (e == null)
924
+ return;
925
+ if (typeof e != "string") {
926
+ r.push({ field: n, message: "Expected a string." });
927
+ return;
928
+ }
929
+ const a = o.trim === !1 ? e : e.trim();
930
+ if (!o.allowEmpty && a.length === 0) {
931
+ r.push({ field: n, message: "Expected a non-empty string." });
932
+ return;
933
+ }
934
+ if (a.length > t) {
935
+ r.push({
936
+ field: n,
937
+ message: `Expected ${t} characters or fewer.`
938
+ });
939
+ return;
940
+ }
941
+ return a;
942
+ }
943
+ function ce(e, n, t) {
944
+ const r = B(e, n, 2e3, t);
945
+ if (r)
946
+ try {
947
+ return new URL(r), r;
948
+ } catch {
949
+ t.push({ field: n, message: "Expected an absolute URL." });
950
+ return;
951
+ }
952
+ }
953
+ function pe(e, n, t) {
954
+ const r = F(e, n, t);
955
+ D(r, n, ["tokens", "components"], t);
956
+ const o = {};
957
+ if (r.tokens !== void 0) {
958
+ const a = F(r.tokens, `${n}.tokens`, t);
959
+ D(
960
+ a,
961
+ `${n}.tokens`,
962
+ ["color", "typography"],
963
+ t
964
+ );
965
+ const i = {};
966
+ if (a.color !== void 0) {
967
+ const c = F(
968
+ a.color,
969
+ `${n}.tokens.color`,
970
+ t
971
+ ), l = [
972
+ "background",
973
+ "foreground",
974
+ "muted",
975
+ "mutedForeground",
976
+ "border",
977
+ "primary",
978
+ "primaryForeground",
979
+ "positive",
980
+ "negative",
981
+ "warning",
982
+ "info"
983
+ ];
984
+ D(c, `${n}.tokens.color`, l, t);
985
+ const d = {};
986
+ l.forEach((m) => {
987
+ const p = B(
988
+ c[m],
989
+ `${n}.tokens.color.${m}`,
990
+ 120,
991
+ t
992
+ );
993
+ p !== void 0 && (d[m] = p);
994
+ }), i.color = d;
995
+ }
996
+ if (a.typography !== void 0) {
997
+ const c = F(
998
+ a.typography,
999
+ `${n}.tokens.typography`,
1000
+ t
1001
+ );
1002
+ D(
1003
+ c,
1004
+ `${n}.tokens.typography`,
1005
+ ["fontFamily", "monoFontFamily"],
1006
+ t
1007
+ );
1008
+ const l = B(
1009
+ c.fontFamily,
1010
+ `${n}.tokens.typography.fontFamily`,
1011
+ 500,
1012
+ t,
1013
+ { allowEmpty: !0 }
1014
+ ), d = B(
1015
+ c.monoFontFamily,
1016
+ `${n}.tokens.typography.monoFontFamily`,
1017
+ 500,
1018
+ t,
1019
+ { allowEmpty: !0 }
1020
+ );
1021
+ i.typography = {
1022
+ ...l !== void 0 ? { fontFamily: l } : {},
1023
+ ...d !== void 0 ? { monoFontFamily: d } : {}
1024
+ };
1025
+ }
1026
+ o.tokens = i;
1027
+ }
1028
+ if (r.components !== void 0) {
1029
+ const a = F(
1030
+ r.components,
1031
+ `${n}.components`,
1032
+ t
1033
+ );
1034
+ if (D(a, `${n}.components`, ["chart"], t), a.chart !== void 0) {
1035
+ const i = F(
1036
+ a.chart,
1037
+ `${n}.components.chart`,
1038
+ t
1039
+ );
1040
+ D(i, `${n}.components.chart`, ["palette"], t);
1041
+ let c;
1042
+ i.palette !== void 0 && (Array.isArray(i.palette) ? i.palette.length > 20 ? t.push({
1043
+ field: `${n}.components.chart.palette`,
1044
+ message: "Expected 20 colors or fewer."
1045
+ }) : c = i.palette.map(
1046
+ (l, d) => B(
1047
+ l,
1048
+ `${n}.components.chart.palette.${d}`,
1049
+ 120,
1050
+ t
1051
+ )
1052
+ ).filter((l) => l !== void 0) : t.push({
1053
+ field: `${n}.components.chart.palette`,
1054
+ message: "Expected an array."
1055
+ })), o.components = {
1056
+ chart: c ? { palette: c } : {}
1057
+ };
1058
+ }
1059
+ }
1060
+ return o;
1061
+ }
1062
+ function Ot(e, n) {
1063
+ const t = "presentation.appearance", r = F(e, t, n);
1064
+ D(r, t, ["version", "schemes"], n);
1065
+ const o = {};
1066
+ if (r.version !== void 0 && (typeof r.version != "number" || !Number.isFinite(r.version) ? n.push({ field: `${t}.version`, message: "Expected a number." }) : o.version = r.version), r.schemes !== void 0) {
1067
+ const a = F(r.schemes, `${t}.schemes`, n);
1068
+ D(a, `${t}.schemes`, ["light", "dark"], n), o.schemes = {
1069
+ ...a.light !== void 0 ? {
1070
+ light: pe(
1071
+ a.light,
1072
+ `${t}.schemes.light`,
1073
+ n
1074
+ )
1075
+ } : {},
1076
+ ...a.dark !== void 0 ? {
1077
+ dark: pe(
1078
+ a.dark,
1079
+ `${t}.schemes.dark`,
1080
+ n
1081
+ )
1082
+ } : {}
1083
+ };
1084
+ }
1085
+ return o;
1086
+ }
1087
+ function Mt(e, n) {
1088
+ const t = "presentation.brandOverrides", r = F(e, t, n);
1089
+ D(r, t, ["brandName", "logoUrl", "link"], n);
1090
+ const o = B(
1091
+ r.brandName,
1092
+ `${t}.brandName`,
1093
+ 200,
1094
+ n
1095
+ ), a = ce(r.logoUrl, `${t}.logoUrl`, n), i = B(r.link, `${t}.link`, 120, n);
1096
+ return {
1097
+ ...o !== void 0 ? { brandName: o } : {},
1098
+ ...a !== void 0 ? { logoUrl: a } : {},
1099
+ ...i !== void 0 ? { link: i } : {}
1100
+ };
1101
+ }
1102
+ function Bt(e, n) {
1103
+ const t = "presentation.fragments", r = F(e, t, n), o = [
1104
+ "preHeaderText",
1105
+ "headerBannerHtml",
1106
+ "signatureHtml",
1107
+ "footerHtml",
1108
+ "disclaimerHtml",
1109
+ "unsubscribeUrl"
1110
+ ];
1111
+ D(r, t, o, n);
1112
+ const a = {};
1113
+ return o.forEach((i) => {
1114
+ const c = i === "unsubscribeUrl" ? ce(r[i], `${t}.${i}`, n) : B(
1115
+ r[i],
1116
+ `${t}.${i}`,
1117
+ i === "preHeaderText" ? 200 : 5e3,
1118
+ n,
1119
+ { trim: i === "preHeaderText" }
1120
+ );
1121
+ c !== void 0 && (a[i] = c);
1122
+ }), a;
1123
+ }
1124
+ function Nt(e) {
1125
+ const n = [], t = {};
1126
+ if (e.appearance !== void 0 && (t.appearance = Ot(e.appearance, n)), e.brandOverrides !== void 0 && (t.brandOverrides = Mt(e.brandOverrides, n)), e.fragments !== void 0 && (t.fragments = Bt(e.fragments, n)), e.viewUrl !== void 0) {
1127
+ const r = ce(e.viewUrl, "presentation.viewUrl", n);
1128
+ r !== void 0 && (t.viewUrl = r);
1129
+ }
1130
+ return { value: t, issues: n };
1131
+ }
1132
+ const U = [
1133
+ "SUN",
1134
+ "MON",
1135
+ "TUE",
1136
+ "WED",
1137
+ "THU",
1138
+ "FRI",
1139
+ "SAT"
1140
+ ], $e = new Map(
1141
+ U.map((e, n) => [e, n])
1142
+ ), j = [1, 2, 3, 4, 5], Ce = [1, 2, 3, 6, 12], Te = {
1143
+ 1: "first",
1144
+ 2: "second",
1145
+ 3: "third",
1146
+ 4: "fourth",
1147
+ [-1]: "last"
1148
+ }, br = {
1149
+ frequency: "weekly",
1150
+ hour: 9,
1151
+ minute: 0,
1152
+ weekdays: [1]
1153
+ }, _ = { ok: !1, issue: "Choose a supported schedule." };
1154
+ function Pt(e) {
1155
+ if (typeof e != "string" || e.length === 0 || e !== e.trim() || /^(?:(?:UTC|GMT)[+-]|[+-]\d{2}:\d{2}$)/.test(e))
1156
+ return !1;
1157
+ try {
1158
+ return new Intl.DateTimeFormat("en-US", { timeZone: e }).format(), !0;
1159
+ } catch {
1160
+ return !1;
1161
+ }
1162
+ }
1163
+ function Lt(e) {
1164
+ return Number.isInteger(e.minute) && e.minute >= 0 && e.minute <= 59 && Number.isInteger(e.hour) && e.hour >= 0 && e.hour <= 23;
1165
+ }
1166
+ function Ee(e) {
1167
+ if (e.length === 0) return null;
1168
+ const n = [...e].sort((t, r) => t - r);
1169
+ return n.some(
1170
+ (t, r) => !Number.isInteger(t) || t < 0 || t > 6 || r > 0 && t === n[r - 1]
1171
+ ) ? null : n;
1172
+ }
1173
+ function xe(e) {
1174
+ const t = [...e.filter((o) => o !== "last")].sort((o, a) => o - a);
1175
+ if (t.some(
1176
+ (o, a) => !Number.isInteger(o) || o < 1 || o > 31 || a > 0 && o === t[a - 1]
1177
+ ) || e.filter((o) => o === "last").length > 1)
1178
+ return null;
1179
+ const r = e.includes("last") ? [...t, "last"] : t;
1180
+ return r.length > 0 ? r : null;
1181
+ }
1182
+ function P(e, n) {
1183
+ const t = [];
1184
+ for (let r = 0; r < 12 / e; r += 1)
1185
+ t.push((n + r * e) % 12);
1186
+ return t.sort((r, o) => r - o);
1187
+ }
1188
+ function zt(e, n) {
1189
+ return e === 1 ? "*" : P(e, n).map((t) => t + 1).join(",");
1190
+ }
1191
+ function Se(e, n) {
1192
+ return e.every((t) => Wt(t, n));
1193
+ }
1194
+ function Ir(e) {
1195
+ if (!Lt(e))
1196
+ throw new Error("Choose a valid schedule time.");
1197
+ const n = `${e.minute} ${e.hour}`;
1198
+ switch (e.frequency) {
1199
+ case "daily":
1200
+ return e.weekdaysOnly ? `${n} * * ${j.map((t) => U[t]).join(",")}` : `${n} * * *`;
1201
+ case "weekly": {
1202
+ const t = Ee(e.weekdays);
1203
+ if (!t) throw new Error("Choose at least one weekday.");
1204
+ return `${n} * * ${t.map((r) => U[r]).join(",")}`;
1205
+ }
1206
+ case "monthly": {
1207
+ if (!Ce.includes(e.interval) || !Number.isInteger(e.startMonth) || e.startMonth < 0 || e.startMonth >= e.interval)
1208
+ throw new Error("Choose a valid month cycle.");
1209
+ const t = zt(e.interval, e.startMonth);
1210
+ if (e.on.type === "days") {
1211
+ const i = xe(e.on.days);
1212
+ if (!i) throw new Error("Choose at least one day of the month.");
1213
+ const c = P(e.interval, e.startMonth);
1214
+ if (!Se(i, c))
1215
+ throw new Error("Choose a day that occurs in the chosen months.");
1216
+ const l = i.map((d) => d === "last" ? "L" : String(d)).join(",");
1217
+ return `${n} ${l} ${t} *`;
1218
+ }
1219
+ const { ordinal: r, weekday: o } = e.on;
1220
+ if (!Number.isInteger(o) || o < 0 || o > 6 || !(r in Te))
1221
+ throw new Error("Choose a valid weekday.");
1222
+ const a = U[o];
1223
+ return `${n} * ${t} ${r === -1 ? `${a}L` : `${a}#${r}`}`;
1224
+ }
1225
+ }
1226
+ }
1227
+ function Kt(e) {
1228
+ if (e === "*") return { interval: 1, startMonth: 0 };
1229
+ const n = e.split(",");
1230
+ if (n.some((i) => !/^([1-9]|1[0-2])$/.test(i))) return null;
1231
+ const t = n.map((i) => Number(i) - 1), r = 12 / t.length;
1232
+ if (!Ce.includes(r))
1233
+ return null;
1234
+ const o = t[0], a = P(
1235
+ r,
1236
+ o
1237
+ );
1238
+ return o >= r || a.length !== t.length || a.some((i, c) => i !== t[c]) ? null : { interval: r, startMonth: o };
1239
+ }
1240
+ function qt(e) {
1241
+ const n = e.split(",");
1242
+ if (n.some((o) => !/^(L|[1-9]|[12]\d|3[01])$/.test(o))) return null;
1243
+ const t = n.map(
1244
+ (o) => o === "L" ? "last" : Number(o)
1245
+ ), r = xe(t);
1246
+ return !r || r.some((o, a) => o !== t[a]) ? null : r;
1247
+ }
1248
+ function Ut(e) {
1249
+ const n = /^([A-Z]{3})(?:#([1-4])|(L))$/.exec(e);
1250
+ if (!n) return null;
1251
+ const t = $e.get(n[1]);
1252
+ return t === void 0 ? null : {
1253
+ weekday: t,
1254
+ ordinal: n[3] ? -1 : Number(n[2])
1255
+ };
1256
+ }
1257
+ function ke(e) {
1258
+ if (typeof e != "string" || e.length === 0 || e !== e.trim() || e.includes(" "))
1259
+ return _;
1260
+ const n = e.split(" ");
1261
+ if (n.length !== 5) return _;
1262
+ const [t, r, o, a, i] = n;
1263
+ if (!/^(0|[1-9]\d?)$/.test(t) || !/^(0|[1-9]\d?)$/.test(r))
1264
+ return _;
1265
+ const c = Number(t), l = Number(r);
1266
+ if (c > 59 || l > 23) return _;
1267
+ if (a === "*" && o === "*" && i === "*")
1268
+ return {
1269
+ ok: !0,
1270
+ value: { frequency: "daily", hour: l, minute: c, weekdaysOnly: !1 }
1271
+ };
1272
+ if (a === "*" && o === "*" && !i.includes("#") && !i.endsWith("L")) {
1273
+ const p = i.split(",").map((I) => $e.get(I));
1274
+ if (p.some((I) => I === void 0)) return _;
1275
+ const f = p, h = Ee(f);
1276
+ return !h || h.some((I, w) => I !== f[w]) ? _ : h.length === j.length && h.every((I, w) => I === j[w]) ? {
1277
+ ok: !0,
1278
+ value: { frequency: "daily", hour: l, minute: c, weekdaysOnly: !0 }
1279
+ } : {
1280
+ ok: !0,
1281
+ value: { frequency: "weekly", hour: l, minute: c, weekdays: h }
1282
+ };
1283
+ }
1284
+ const d = Kt(a);
1285
+ if (!d) return _;
1286
+ if (o !== "*" && i === "*") {
1287
+ const m = qt(o), p = P(d.interval, d.startMonth);
1288
+ return !m || !Se(m, p) ? _ : {
1289
+ ok: !0,
1290
+ value: {
1291
+ frequency: "monthly",
1292
+ hour: l,
1293
+ minute: c,
1294
+ ...d,
1295
+ on: { type: "days", days: m }
1296
+ }
1297
+ };
1298
+ }
1299
+ if (o === "*" && i !== "*") {
1300
+ const m = Ut(i);
1301
+ return m ? {
1302
+ ok: !0,
1303
+ value: {
1304
+ frequency: "monthly",
1305
+ hour: l,
1306
+ minute: c,
1307
+ ...d,
1308
+ on: { type: "weekday", ...m }
1309
+ }
1310
+ } : _;
1311
+ }
1312
+ return _;
1313
+ }
1314
+ function Vt(e, n, t) {
1315
+ return new Intl.DateTimeFormat(t, {
1316
+ hour: "numeric",
1317
+ minute: "2-digit",
1318
+ timeZone: "UTC"
1319
+ }).format(new Date(Date.UTC(2020, 0, 1, e, n)));
1320
+ }
1321
+ function jt(e, n) {
1322
+ var t;
1323
+ if (e === "UTC") return "UTC";
1324
+ try {
1325
+ return ((t = new Intl.DateTimeFormat(n, {
1326
+ timeZone: e,
1327
+ timeZoneName: "longGeneric"
1328
+ }).formatToParts(new Date(Date.UTC(2020, 0, 1))).find((o) => o.type === "timeZoneName")) == null ? void 0 : t.value) ?? e;
1329
+ } catch {
1330
+ return null;
1331
+ }
1332
+ }
1333
+ function he(e) {
1334
+ return e.length <= 1 ? e.join("") : e.length === 2 ? `${e[0]} and ${e[1]}` : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
1335
+ }
1336
+ function Ht(e) {
1337
+ const n = e % 100;
1338
+ return n >= 11 && n <= 13 ? `${e}th` : `${e}${["th", "st", "nd", "rd"][e % 10] ?? "th"}`;
1339
+ }
1340
+ function Gt(e, n, t) {
1341
+ const r = (a, i) => new Intl.DateTimeFormat(t, { month: i, timeZone: "UTC" }).format(
1342
+ new Date(Date.UTC(2020, a, 1))
1343
+ );
1344
+ if (e === 1) return "every month";
1345
+ if (e === 12) return `${r(n, "long")} each year`;
1346
+ const o = P(e, n).map((a) => r(a, "short")).join(", ");
1347
+ return e === 3 ? `each quarter (${o})` : `every ${e} months (${o})`;
1348
+ }
1349
+ function wr(e, n, t = "en-US") {
1350
+ const r = ke(e);
1351
+ if (!r.ok) return null;
1352
+ try {
1353
+ const o = r.value, a = jt(n, t);
1354
+ if (!a) return null;
1355
+ const i = `at ${Vt(o.hour, o.minute, t)} ${a}`, c = (l) => new Intl.DateTimeFormat(t, {
1356
+ weekday: "long",
1357
+ timeZone: "UTC"
1358
+ }).format(new Date(Date.UTC(2023, 0, 1 + l)));
1359
+ switch (o.frequency) {
1360
+ case "daily":
1361
+ return o.weekdaysOnly ? `Every weekday, Monday to Friday, ${i}` : `Every day ${i}`;
1362
+ case "weekly":
1363
+ return `Every ${he(o.weekdays.map(c))} ${i}`;
1364
+ case "monthly": {
1365
+ const l = Gt(o.interval, o.startMonth, t);
1366
+ if (o.on.type === "weekday")
1367
+ return `On the ${Te[o.on.ordinal]} ${c(o.on.weekday)} of ${l} ${i}`;
1368
+ const d = o.on.days.map(
1369
+ (m) => m === "last" ? "last day" : Ht(m)
1370
+ );
1371
+ return `On the ${he(d)} of ${l} ${i}`;
1372
+ }
1373
+ }
1374
+ } catch {
1375
+ return null;
1376
+ }
1377
+ }
1378
+ const _e = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1379
+ function Wt(e, n) {
1380
+ return e === "last" || n.some((t) => e <= _e[t]);
1381
+ }
1382
+ function $r(e) {
1383
+ if (e.frequency !== "monthly" || e.on.type !== "days") return null;
1384
+ const n = e.on.days.filter((o) => o !== "last");
1385
+ if (n.length === 0) return null;
1386
+ const t = Math.max(...n), r = P(e.interval, e.startMonth).filter(
1387
+ (o) => t > (o === 1 ? 28 : _e[o])
1388
+ );
1389
+ return r.length > 0 ? { day: t, months: r } : null;
1390
+ }
1391
+ function Zt(e, n) {
1392
+ return new Date(Date.UTC(e, n + 1, 0)).getUTCDate();
1393
+ }
1394
+ function Qt(e, n, t, r) {
1395
+ const o = new Date(Date.UTC(n, t, r)).getUTCDay();
1396
+ switch (e.frequency) {
1397
+ case "daily":
1398
+ return !e.weekdaysOnly || j.includes(o);
1399
+ case "weekly":
1400
+ return e.weekdays.includes(o);
1401
+ case "monthly": {
1402
+ if (!P(e.interval, e.startMonth).includes(t))
1403
+ return !1;
1404
+ const a = Zt(n, t);
1405
+ return e.on.type === "days" ? e.on.days.some(
1406
+ (i) => i === "last" ? r === a : i === r
1407
+ ) : o !== e.on.weekday ? !1 : e.on.ordinal === -1 ? r + 7 > a : Math.ceil(r / 7) === e.on.ordinal;
1408
+ }
1409
+ }
1410
+ }
1411
+ function Cr(e, n, t, r) {
1412
+ const o = ke(e);
1413
+ if (!o.ok || !Pt(n)) return [];
1414
+ const a = o.value, i = new Intl.DateTimeFormat("en-US", {
1415
+ timeZone: n,
1416
+ hourCycle: "h23",
1417
+ year: "numeric",
1418
+ month: "numeric",
1419
+ day: "numeric",
1420
+ hour: "numeric",
1421
+ minute: "numeric"
1422
+ }).formatToParts(t), c = (m) => {
1423
+ var p;
1424
+ return Number((p = i.find((f) => f.type === m)) == null ? void 0 : p.value);
1425
+ }, l = new Date(Date.UTC(c("year"), c("month") - 1, c("day")));
1426
+ c("hour") * 60 + c("minute") >= a.hour * 60 + a.minute && l.setUTCDate(l.getUTCDate() + 1);
1427
+ const d = [];
1428
+ for (let m = 0; m < 366 * 4 * (r + 1) && d.length < r; m += 1)
1429
+ Qt(a, l.getUTCFullYear(), l.getUTCMonth(), l.getUTCDate()) && d.push(l.toISOString().slice(0, 10)), l.setUTCDate(l.getUTCDate() + 1);
1430
+ return d;
1431
+ }
1432
+ function Tr(e) {
1433
+ return e != null && e.role ? e.type === "tenant" ? e.role === "POWER_USER" : ["AUTHOR", "ADMIN", "SUPER_ADMIN"].includes(e.role) : !1;
1434
+ }
1435
+ function Er(e) {
1436
+ return e.canCreate ? [
1437
+ ...e.scheduledReportAvailable ? ["scheduled_report"] : [],
1438
+ ...e.analyticalBriefingsEnabled ? ["analytical_briefing"] : []
1439
+ ] : [];
1440
+ }
1441
+ function Xt(e) {
1442
+ const n = (e == null ? void 0 : e.channels) ?? [];
1443
+ return n.length === 1 && n[0] === "EMAIL";
1444
+ }
1445
+ function Yt(e) {
1446
+ return e.body.type === "generated_analysis" ? "Analytical briefing" : e.body.type === "custom_message" && e.attachments.length > 0 && Xt(e.deliveryConfig) ? e.scheduleExpr ? "Scheduled report" : "On-demand report" : "Plain briefing";
1447
+ }
1448
+ function xr(e) {
1449
+ const n = Yt(e), t = n === "Scheduled report" || n === "On-demand report" ? "report" : "briefing";
1450
+ return {
1451
+ typeLabel: n,
1452
+ noun: t,
1453
+ pluralNoun: t === "report" ? "reports" : "briefings"
1454
+ };
1455
+ }
1456
+ const ne = "BRIEFING", Jt = ["markdown", "html"], re = ["markdown"], X = 20, u = {
1457
+ name: 500,
1458
+ description: 2e3,
1459
+ instruction: 5e4,
1460
+ customMessage: 5e4,
1461
+ contentTitle: 500,
1462
+ contentSummary: 2e4,
1463
+ contentText: 5e3,
1464
+ contentSql: 5e4,
1465
+ contentItem: 2e3,
1466
+ contentCell: 500,
1467
+ attachmentTitle: 500,
1468
+ presentationAudience: 1e3,
1469
+ presentationTone: 500,
1470
+ presentationFormat: 2e3,
1471
+ id: 500
1472
+ }, S = {
1473
+ maxBlocks: 50,
1474
+ maxTableRows: 100,
1475
+ maxTableColumns: 20,
1476
+ maxTableCellCharacters: u.contentCell,
1477
+ maxParagraphCharacters: u.contentText,
1478
+ maxFindingCharacters: u.contentText,
1479
+ maxListItems: 100,
1480
+ // A kpi_grid is rendered as a 2-up tile arrangement in emails. Cap at 8 so
1481
+ // the visual stays at most 4 rows (4 columns wide on desktop would force
1482
+ // tiny tiles in narrow client panels; 2-up was the chosen layout).
1483
+ maxKpiTiles: 8
1484
+ };
1485
+ function en(e) {
1486
+ if (e === null || typeof e != "object" || Array.isArray(e))
1487
+ return !1;
1488
+ const n = e;
1489
+ if (typeof n.value != "number" || !Number.isFinite(n.value))
1490
+ return !1;
1491
+ const t = n.target;
1492
+ if (t === null || typeof t != "object" || Array.isArray(t))
1493
+ return !1;
1494
+ const r = t;
1495
+ return (r.kind === "metric" && typeof r.metricId == "string" && !!r.metricId.trim() || r.kind === "column" && typeof r.columnKey == "string" && !!r.columnKey.trim() || r.kind === "matrix_measure" && typeof r.measureId == "string" && !!r.measureId.trim()) && ye(n.format).ok;
1496
+ }
1497
+ function tn(e) {
1498
+ return e == null ? "" : en(e) ? He(e.value, e.format) : String(e);
1499
+ }
1500
+ function Sr(e) {
1501
+ return [e.delta, e.percentChange].filter(
1502
+ (n) => n != null
1503
+ ).map(tn).filter(Boolean).join(" / ");
1504
+ }
1505
+ const Ae = new Set(Jt), nn = /* @__PURE__ */ new Set([
1506
+ "EMAIL",
1507
+ "WEBHOOK",
1508
+ "SLACK",
1509
+ "IN_APP",
1510
+ "TELEGRAM"
1511
+ ]), Y = {
1512
+ maxToolCalls: { min: 1, max: 100 },
1513
+ maxPlanningIterations: { min: 1, max: 10 },
1514
+ maxRows: { min: 1, max: 1e5 },
1515
+ timeoutMs: { min: 1e3, max: 30 * 6e4 }
1516
+ }, rn = /* @__PURE__ */ new Set([
1517
+ "letter",
1518
+ "legal",
1519
+ "a4",
1520
+ "a3",
1521
+ "tabloid"
1522
+ ]), on = /* @__PURE__ */ new Set([
1523
+ "portrait",
1524
+ "landscape"
1525
+ ]), an = /* @__PURE__ */ new Set([",", ";", " "]), cn = new Set(Ze), ln = /* @__PURE__ */ new Set([
1526
+ "current",
1527
+ "all"
1528
+ ]), dn = /* @__PURE__ */ new Set([
1529
+ "concise",
1530
+ "balanced",
1531
+ "detailed"
1532
+ ]), sn = /* @__PURE__ */ new Set([
1533
+ "info",
1534
+ "positive",
1535
+ "warning",
1536
+ "critical"
1537
+ ]), mn = /* @__PURE__ */ new Set([
1538
+ "text",
1539
+ "number",
1540
+ "currency",
1541
+ "percent",
1542
+ "date",
1543
+ "boolean"
1544
+ ]), un = /* @__PURE__ */ new Set([
1545
+ "left",
1546
+ "center",
1547
+ "right"
1548
+ ]), fn = [
1549
+ "matrix",
1550
+ "pageSize",
1551
+ "orientation",
1552
+ "includeFilters",
1553
+ "includeTimestamp",
1554
+ "delimiter",
1555
+ "csvEncoding",
1556
+ "includeHeaders",
1557
+ "useFormattedValues",
1558
+ "sheetSelection",
1559
+ "currentSheetId",
1560
+ "currentSheetName",
1561
+ "filterValues",
1562
+ "inlineFilterValues",
1563
+ "sheetFilterValues",
1564
+ // Saved by earlier versions and still accepted, then dropped: each run
1565
+ // builds its filter line from `filterValues` at its own time.
1566
+ "filterLine",
1567
+ "controlValues",
1568
+ "controlDefinitions",
1569
+ "cardControlDefinitions",
1570
+ "controlBindings",
1571
+ "tablePreferences",
1572
+ "dashboardInputExecutionSnapshot",
1573
+ "printInputCapture",
1574
+ "selectedSheetId",
1575
+ "cardType",
1576
+ "allowDownload",
1577
+ "theme"
1578
+ ];
1579
+ class W extends Error {
1580
+ constructor(t) {
1581
+ super(t.map((r) => `${r.field}: ${r.message}`).join("; "));
1582
+ K(this, "issues");
1583
+ this.name = "BriefingContractError", this.issues = t;
1584
+ }
1585
+ }
1586
+ function Fe(e) {
1587
+ return typeof e == "object" && e !== null && !Array.isArray(e);
1588
+ }
1589
+ function s(e, n, t) {
1590
+ e.push({ field: n, message: t });
1591
+ }
1592
+ function $(e, n, t) {
1593
+ return Fe(e) ? e : (s(t, n, "Expected an object."), {});
1594
+ }
1595
+ function y(e, n, t, r) {
1596
+ const o = new Set(t);
1597
+ Object.keys(e).forEach((a) => {
1598
+ o.has(a) || s(
1599
+ r,
1600
+ n ? `${n}.${a}` : a,
1601
+ `Unexpected field "${a}".`
1602
+ );
1603
+ });
1604
+ }
1605
+ function v(e, n, t, r) {
1606
+ if (typeof e != "string")
1607
+ return s(r, n, "Expected a string."), "";
1608
+ const o = e.trim();
1609
+ return o ? (o.length > t && s(r, n, `Must be ${t} characters or fewer.`), o) : (s(r, n, "Required value cannot be empty."), "");
1610
+ }
1611
+ function b(e, n, t, r) {
1612
+ if (e == null)
1613
+ return;
1614
+ if (typeof e != "string") {
1615
+ s(r, n, "Expected a string.");
1616
+ return;
1617
+ }
1618
+ const o = e.trim();
1619
+ if (o)
1620
+ return o.length > t && s(r, n, `Must be ${t} characters or fewer.`), o;
1621
+ }
1622
+ function pn(e, n, t, r) {
1623
+ if (typeof e != "string")
1624
+ return s(r, n, "Expected a string."), "";
1625
+ const o = e.trim();
1626
+ return o.length > t && s(r, n, `Must be ${t} characters or fewer.`), o;
1627
+ }
1628
+ function hn(e, n, t) {
1629
+ if (e != null) {
1630
+ if (!Number.isInteger(e) || Number(e) < 0) {
1631
+ s(t, n, "Expected a non-negative integer.");
1632
+ return;
1633
+ }
1634
+ return Number(e);
1635
+ }
1636
+ }
1637
+ function A(e, n, t, r = {}) {
1638
+ if (e == null)
1639
+ return r.required ? (s(t, n, "Expected at least one evidence id."), []) : void 0;
1640
+ if (!Array.isArray(e))
1641
+ return s(t, n, "Expected an array."), r.required ? [] : void 0;
1642
+ const o = [];
1643
+ return e.forEach((a, i) => {
1644
+ const c = v(
1645
+ a,
1646
+ `${n}.${i}`,
1647
+ u.id,
1648
+ t
1649
+ );
1650
+ c && !o.includes(c) && o.push(c);
1651
+ }), r.required && o.length === 0 && s(t, n, "Expected at least one evidence id."), o.length > 0 || r.required ? o : void 0;
1652
+ }
1653
+ function N(e, n, t, r) {
1654
+ return e == null ? n : typeof e != "boolean" ? (s(r, t, "Expected a boolean."), n) : e;
1655
+ }
1656
+ function yn(e, n) {
1657
+ return e == null ? "ACTIVE" : e === "ACTIVE" || e === "PAUSED" || e === "DISABLED" ? e : (s(n, "status", "Expected ACTIVE, PAUSED, or DISABLED."), "ACTIVE");
1658
+ }
1659
+ function gn(e) {
1660
+ return e.includes("@") && e.includes(".") && !e.includes(" ");
1661
+ }
1662
+ function De(e, n) {
1663
+ if (e == null)
1664
+ return { type: "project" };
1665
+ const t = $(e, "source", n), r = t.type;
1666
+ return r === "project" ? (y(t, "source", ["type"], n), { type: "project" }) : r === "dashboard" ? (y(t, "source", ["type", "dashboardId"], n), {
1667
+ type: "dashboard",
1668
+ dashboardId: v(
1669
+ t.dashboardId,
1670
+ "source.dashboardId",
1671
+ u.id,
1672
+ n
1673
+ )
1674
+ }) : (s(n, "source.type", "Expected project or dashboard."), { type: "project" });
1675
+ }
1676
+ function Re(e, n) {
1677
+ const t = $(e, "body", n), r = t.type;
1678
+ return r === "generated_analysis" ? (y(t, "body", ["type", "instruction"], n), {
1679
+ type: "generated_analysis",
1680
+ instruction: v(
1681
+ t.instruction,
1682
+ "body.instruction",
1683
+ u.instruction,
1684
+ n
1685
+ )
1686
+ }) : r === "custom_message" ? (y(t, "body", ["type", "message"], n), {
1687
+ type: "custom_message",
1688
+ message: pn(
1689
+ t.message,
1690
+ "body.message",
1691
+ u.customMessage,
1692
+ n
1693
+ )
1694
+ }) : r === "none" ? (y(t, "body", ["type"], n), { type: "none" }) : (s(
1695
+ n,
1696
+ "body.type",
1697
+ "Expected generated_analysis, custom_message, or none."
1698
+ ), { type: "none" });
1699
+ }
1700
+ function vn(e, n) {
1701
+ if (e == null)
1702
+ return [...re];
1703
+ if (!Array.isArray(e))
1704
+ return s(n, "presentation.artifactFormats", "Expected an array."), [...re];
1705
+ if (e.length === 0)
1706
+ return s(
1707
+ n,
1708
+ "presentation.artifactFormats",
1709
+ "Choose at least one artifact format."
1710
+ ), [];
1711
+ const t = [];
1712
+ return e.forEach((r, o) => {
1713
+ if (typeof r != "string" || !Ae.has(r)) {
1714
+ s(
1715
+ n,
1716
+ `presentation.artifactFormats.${o}`,
1717
+ "Expected markdown or html."
1718
+ );
1719
+ return;
1720
+ }
1721
+ t.includes(r) || t.push(r);
1722
+ }), t;
1723
+ }
1724
+ function Oe(e, n) {
1725
+ if (e == null)
1726
+ return {
1727
+ artifactFormats: [...re],
1728
+ includeEvidence: !0,
1729
+ includeSql: !0
1730
+ };
1731
+ const t = $(e, "presentation", n);
1732
+ y(
1733
+ t,
1734
+ "presentation",
1735
+ [
1736
+ "artifactFormats",
1737
+ "includeEvidence",
1738
+ "includeSql",
1739
+ "audience",
1740
+ "tone",
1741
+ "format",
1742
+ "appearance",
1743
+ "brandOverrides",
1744
+ "fragments",
1745
+ "viewUrl"
1746
+ ],
1747
+ n
1748
+ );
1749
+ const r = {
1750
+ artifactFormats: vn(t.artifactFormats, n),
1751
+ includeEvidence: N(
1752
+ t.includeEvidence,
1753
+ !0,
1754
+ "presentation.includeEvidence",
1755
+ n
1756
+ ),
1757
+ includeSql: N(
1758
+ t.includeSql,
1759
+ !0,
1760
+ "presentation.includeSql",
1761
+ n
1762
+ )
1763
+ }, o = b(
1764
+ t.audience,
1765
+ "presentation.audience",
1766
+ u.presentationAudience,
1767
+ n
1768
+ ), a = b(
1769
+ t.tone,
1770
+ "presentation.tone",
1771
+ u.presentationTone,
1772
+ n
1773
+ ), i = b(
1774
+ t.format,
1775
+ "presentation.format",
1776
+ u.presentationFormat,
1777
+ n
1778
+ );
1779
+ o && (r.audience = o), a && (r.tone = a), i && (r.format = i);
1780
+ const c = Nt(t);
1781
+ return c.issues.forEach((l) => s(n, l.field, l.message)), Object.assign(r, c.value), r;
1782
+ }
1783
+ function bn(e, n, t) {
1784
+ return Array.isArray(e) ? (e.length === 0 && s(t, n, "Expected at least one item."), e.length > S.maxListItems && s(
1785
+ t,
1786
+ n,
1787
+ `Must have ${S.maxListItems} items or fewer.`
1788
+ ), e.slice(0, S.maxListItems).map(
1789
+ (r, o) => v(
1790
+ r,
1791
+ `${n}.${o}`,
1792
+ u.contentItem,
1793
+ t
1794
+ )
1795
+ ).filter(Boolean)) : (s(t, n, "Expected an array."), []);
1796
+ }
1797
+ function In(e, n, t) {
1798
+ const r = $(e, n, t);
1799
+ if (r.kind === "metric")
1800
+ return y(r, n, ["kind", "metricId"], t), {
1801
+ kind: "metric",
1802
+ metricId: v(
1803
+ r.metricId,
1804
+ `${n}.metricId`,
1805
+ u.id,
1806
+ t
1807
+ )
1808
+ };
1809
+ if (r.kind === "column")
1810
+ return y(r, n, ["kind", "columnKey"], t), {
1811
+ kind: "column",
1812
+ columnKey: v(
1813
+ r.columnKey,
1814
+ `${n}.columnKey`,
1815
+ u.id,
1816
+ t
1817
+ )
1818
+ };
1819
+ if (r.kind === "matrix_measure")
1820
+ return y(r, n, ["kind", "measureId"], t), {
1821
+ kind: "matrix_measure",
1822
+ measureId: v(
1823
+ r.measureId,
1824
+ `${n}.measureId`,
1825
+ u.id,
1826
+ t
1827
+ )
1828
+ };
1829
+ s(
1830
+ t,
1831
+ `${n}.kind`,
1832
+ "Expected metric, column, or matrix_measure."
1833
+ );
1834
+ }
1835
+ function Me(e, n, t) {
1836
+ if (e === null || typeof e != "object" || Array.isArray(e))
1837
+ return;
1838
+ const r = $(e, n, t);
1839
+ if (!Object.prototype.hasOwnProperty.call(r, "target") && !Object.prototype.hasOwnProperty.call(r, "format"))
1840
+ return;
1841
+ y(r, n, ["value", "target", "format"], t), (typeof r.value != "number" || !Number.isFinite(r.value)) && s(t, `${n}.value`, "Expected a finite number.");
1842
+ const o = In(
1843
+ r.target,
1844
+ `${n}.target`,
1845
+ t
1846
+ ), a = ye(r.format);
1847
+ if (a.ok || a.issues.forEach(
1848
+ (i) => s(
1849
+ t,
1850
+ i.path === "$" ? `${n}.format` : `${n}.format.${i.path}`,
1851
+ i.message
1852
+ )
1853
+ ), !(typeof r.value != "number" || !Number.isFinite(r.value) || !o || !a.ok))
1854
+ return { value: r.value, target: o, format: a.value };
1855
+ }
1856
+ function M(e, n, t) {
1857
+ if (typeof e == "string")
1858
+ return e;
1859
+ if (typeof e == "number") {
1860
+ if (!Number.isFinite(e)) {
1861
+ s(t, n, "Expected a finite number.");
1862
+ return;
1863
+ }
1864
+ return e;
1865
+ }
1866
+ const r = Me(e, n, t);
1867
+ if (r) return r;
1868
+ s(
1869
+ t,
1870
+ n,
1871
+ "Expected a string, number, or structured numeric value."
1872
+ );
1873
+ }
1874
+ function wn(e, n, t) {
1875
+ if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean")
1876
+ return typeof e == "string" && e.length > u.contentCell ? (s(
1877
+ t,
1878
+ n,
1879
+ `Must be ${u.contentCell} characters or fewer.`
1880
+ ), e.slice(0, u.contentCell)) : typeof e == "number" && !Number.isFinite(e) ? (s(t, n, "Expected a finite number."), null) : e;
1881
+ const r = Me(e, n, t);
1882
+ return r || (s(
1883
+ t,
1884
+ n,
1885
+ "Expected a string, number, boolean, structured numeric value, or null."
1886
+ ), null);
1887
+ }
1888
+ function $n(e, n, t) {
1889
+ if (!Array.isArray(e))
1890
+ return s(t, n, "Expected an array."), [];
1891
+ e.length === 0 && s(t, n, "Expected at least one column."), e.length > S.maxTableColumns && s(
1892
+ t,
1893
+ n,
1894
+ `Must have ${S.maxTableColumns} columns or fewer.`
1895
+ );
1896
+ const r = /* @__PURE__ */ new Set();
1897
+ return e.slice(0, S.maxTableColumns).map((o, a) => {
1898
+ const i = `${n}.${a}`, c = $(o, i, t);
1899
+ y(c, i, ["key", "label", "kind", "align"], t);
1900
+ const l = v(
1901
+ c.key,
1902
+ `${i}.key`,
1903
+ u.id,
1904
+ t
1905
+ );
1906
+ l && (r.has(l) && s(t, `${i}.key`, "Column key must be unique."), r.add(l));
1907
+ const d = v(
1908
+ c.label,
1909
+ `${i}.label`,
1910
+ u.contentTitle,
1911
+ t
1912
+ ), m = R(
1913
+ c.kind,
1914
+ `${i}.kind`,
1915
+ mn,
1916
+ "text, number, currency, percent, date, or boolean",
1917
+ t
1918
+ ), p = R(
1919
+ c.align,
1920
+ `${i}.align`,
1921
+ un,
1922
+ "left, center, or right",
1923
+ t
1924
+ );
1925
+ return {
1926
+ key: l,
1927
+ label: d,
1928
+ ...m ? { kind: m } : {},
1929
+ ...p ? { align: p } : {}
1930
+ };
1931
+ });
1932
+ }
1933
+ function Cn(e, n, t, r) {
1934
+ if (!Array.isArray(e))
1935
+ return s(r, n, "Expected an array."), [];
1936
+ e.length > S.maxTableRows && s(
1937
+ r,
1938
+ n,
1939
+ `Must have ${S.maxTableRows} rows or fewer.`
1940
+ );
1941
+ const o = new Set(t.map((a) => a.key).filter(Boolean));
1942
+ return e.slice(0, S.maxTableRows).map((a, i) => {
1943
+ const c = `${n}.${i}`, l = $(a, c, r);
1944
+ return Object.keys(l).forEach((d) => {
1945
+ o.has(d) || s(r, `${c}.${d}`, `Unexpected table cell "${d}".`);
1946
+ }), Object.fromEntries(
1947
+ t.map((d) => [
1948
+ d.key,
1949
+ wn(l[d.key] ?? null, `${c}.${d.key}`, r)
1950
+ ])
1951
+ );
1952
+ });
1953
+ }
1954
+ function Tn(e, n, t) {
1955
+ const r = `content.blocks.${n}`, o = $(e, r, t), a = o.type;
1956
+ if (a === "heading") {
1957
+ y(o, r, ["type", "text", "level", "evidenceIds"], t);
1958
+ const i = o.level === void 0 || o.level === null ? void 0 : o.level === 2 || o.level === 3 ? o.level : void 0;
1959
+ o.level !== void 0 && o.level !== null && i === void 0 && s(t, `${r}.level`, "Expected 2 or 3.");
1960
+ const c = A(o.evidenceIds, `${r}.evidenceIds`, t);
1961
+ return {
1962
+ type: "heading",
1963
+ text: v(
1964
+ o.text,
1965
+ `${r}.text`,
1966
+ u.contentTitle,
1967
+ t
1968
+ ),
1969
+ ...i ? { level: i } : {},
1970
+ ...c ? { evidenceIds: c } : {}
1971
+ };
1972
+ }
1973
+ if (a === "paragraph") {
1974
+ y(o, r, ["type", "text", "evidenceIds"], t);
1975
+ const i = A(o.evidenceIds, `${r}.evidenceIds`, t);
1976
+ return {
1977
+ type: "paragraph",
1978
+ text: v(
1979
+ o.text,
1980
+ `${r}.text`,
1981
+ u.contentText,
1982
+ t
1983
+ ),
1984
+ ...i ? { evidenceIds: i } : {}
1985
+ };
1986
+ }
1987
+ if (a === "finding") {
1988
+ y(o, r, ["type", "title", "text", "severity", "evidenceIds"], t);
1989
+ const i = b(
1990
+ o.title,
1991
+ `${r}.title`,
1992
+ u.contentTitle,
1993
+ t
1994
+ ), c = R(
1995
+ o.severity,
1996
+ `${r}.severity`,
1997
+ sn,
1998
+ "info, positive, warning, or critical",
1999
+ t
2000
+ );
2001
+ return {
2002
+ type: "finding",
2003
+ ...i ? { title: i } : {},
2004
+ text: v(
2005
+ o.text,
2006
+ `${r}.text`,
2007
+ u.contentText,
2008
+ t
2009
+ ),
2010
+ ...c ? { severity: c } : {},
2011
+ evidenceIds: A(o.evidenceIds, `${r}.evidenceIds`, t, {
2012
+ required: !0
2013
+ }) ?? []
2014
+ };
2015
+ }
2016
+ if (a === "bullets" || a === "actions" || a === "limitations") {
2017
+ y(o, r, ["type", "title", "items", "evidenceIds"], t);
2018
+ const i = b(
2019
+ o.title,
2020
+ `${r}.title`,
2021
+ u.contentTitle,
2022
+ t
2023
+ ), c = A(o.evidenceIds, `${r}.evidenceIds`, t);
2024
+ return {
2025
+ type: a,
2026
+ ...i ? { title: i } : {},
2027
+ items: bn(o.items, `${r}.items`, t),
2028
+ ...c ? { evidenceIds: c } : {}
2029
+ };
2030
+ }
2031
+ if (a === "metric") {
2032
+ y(
2033
+ o,
2034
+ r,
2035
+ [
2036
+ "type",
2037
+ "label",
2038
+ "value",
2039
+ "previousValue",
2040
+ "delta",
2041
+ "percentChange",
2042
+ "unit",
2043
+ "evidenceIds"
2044
+ ],
2045
+ t
2046
+ );
2047
+ const i = M(o.value, `${r}.value`, t) ?? "";
2048
+ i === "" && s(
2049
+ t,
2050
+ `${r}.value`,
2051
+ "Expected a non-empty string, number, or structured numeric value."
2052
+ );
2053
+ const c = o.previousValue === void 0 || o.previousValue === null ? o.previousValue : M(
2054
+ o.previousValue,
2055
+ `${r}.previousValue`,
2056
+ t
2057
+ ), l = o.delta === void 0 || o.delta === null ? o.delta : M(
2058
+ o.delta,
2059
+ `${r}.delta`,
2060
+ t
2061
+ ), d = o.percentChange === void 0 || o.percentChange === null ? o.percentChange : M(
2062
+ o.percentChange,
2063
+ `${r}.percentChange`,
2064
+ t
2065
+ ), m = b(
2066
+ o.unit,
2067
+ `${r}.unit`,
2068
+ u.contentTitle,
2069
+ t
2070
+ ), p = A(o.evidenceIds, `${r}.evidenceIds`, t);
2071
+ return {
2072
+ type: "metric",
2073
+ label: v(
2074
+ o.label,
2075
+ `${r}.label`,
2076
+ u.contentTitle,
2077
+ t
2078
+ ),
2079
+ value: i,
2080
+ ...c !== void 0 ? { previousValue: c } : {},
2081
+ ...l !== void 0 ? { delta: l } : {},
2082
+ ...d !== void 0 ? { percentChange: d } : {},
2083
+ ...m ? { unit: m } : {},
2084
+ ...p ? { evidenceIds: p } : {}
2085
+ };
2086
+ }
2087
+ if (a === "kpi_grid") {
2088
+ y(o, r, ["type", "title", "tiles", "evidenceIds"], t);
2089
+ const i = b(
2090
+ o.title,
2091
+ `${r}.title`,
2092
+ u.contentTitle,
2093
+ t
2094
+ ), c = Array.isArray(o.tiles) ? o.tiles : [];
2095
+ Array.isArray(o.tiles) || s(t, `${r}.tiles`, "Expected an array."), c.length === 0 && s(t, `${r}.tiles`, "Expected at least one tile."), c.length > S.maxKpiTiles && s(
2096
+ t,
2097
+ `${r}.tiles`,
2098
+ `Must have ${S.maxKpiTiles} tiles or fewer.`
2099
+ );
2100
+ const l = c.slice(0, S.maxKpiTiles).map((m, p) => {
2101
+ const f = `${r}.tiles.${p}`, h = $(m, f, t);
2102
+ y(
2103
+ h,
2104
+ f,
2105
+ [
2106
+ "label",
2107
+ "value",
2108
+ "previousValue",
2109
+ "delta",
2110
+ "percentChange",
2111
+ "unit",
2112
+ "evidenceIds"
2113
+ ],
2114
+ t
2115
+ );
2116
+ const I = M(
2117
+ h.value,
2118
+ `${f}.value`,
2119
+ t
2120
+ ) ?? "";
2121
+ I === "" && s(
2122
+ t,
2123
+ `${f}.value`,
2124
+ "Expected a non-empty string, number, or structured numeric value."
2125
+ );
2126
+ const w = h.previousValue === void 0 || h.previousValue === null ? h.previousValue : M(
2127
+ h.previousValue,
2128
+ `${f}.previousValue`,
2129
+ t
2130
+ ), x = h.delta === void 0 || h.delta === null ? h.delta : M(
2131
+ h.delta,
2132
+ `${f}.delta`,
2133
+ t
2134
+ ), k = h.percentChange === void 0 || h.percentChange === null ? h.percentChange : M(
2135
+ h.percentChange,
2136
+ `${f}.percentChange`,
2137
+ t
2138
+ ), C = b(
2139
+ h.unit,
2140
+ `${f}.unit`,
2141
+ u.contentTitle,
2142
+ t
2143
+ ), E = A(
2144
+ h.evidenceIds,
2145
+ `${f}.evidenceIds`,
2146
+ t
2147
+ );
2148
+ return {
2149
+ label: v(
2150
+ h.label,
2151
+ `${f}.label`,
2152
+ u.contentTitle,
2153
+ t
2154
+ ),
2155
+ value: I,
2156
+ ...w !== void 0 ? { previousValue: w } : {},
2157
+ ...x !== void 0 ? { delta: x } : {},
2158
+ ...k !== void 0 ? { percentChange: k } : {},
2159
+ ...C ? { unit: C } : {},
2160
+ ...E ? { evidenceIds: E } : {}
2161
+ };
2162
+ }), d = A(
2163
+ o.evidenceIds,
2164
+ `${r}.evidenceIds`,
2165
+ t
2166
+ );
2167
+ return {
2168
+ type: "kpi_grid",
2169
+ ...i ? { title: i } : {},
2170
+ tiles: l,
2171
+ ...d ? { evidenceIds: d } : {}
2172
+ };
2173
+ }
2174
+ if (a === "progress") {
2175
+ y(o, r, ["type", "label", "value", "detail", "evidenceIds"], t);
2176
+ const i = typeof o.value == "number" && Number.isFinite(o.value) ? o.value : 0;
2177
+ (typeof o.value != "number" || !Number.isFinite(o.value)) && s(t, `${r}.value`, "Expected a finite number.");
2178
+ const c = b(
2179
+ o.detail,
2180
+ `${r}.detail`,
2181
+ u.contentText,
2182
+ t
2183
+ ), l = A(o.evidenceIds, `${r}.evidenceIds`, t);
2184
+ return {
2185
+ type: "progress",
2186
+ label: v(
2187
+ o.label,
2188
+ `${r}.label`,
2189
+ u.contentTitle,
2190
+ t
2191
+ ),
2192
+ value: i,
2193
+ ...c ? { detail: c } : {},
2194
+ ...l ? { evidenceIds: l } : {}
2195
+ };
2196
+ }
2197
+ if (a === "table") {
2198
+ y(
2199
+ o,
2200
+ r,
2201
+ ["type", "id", "title", "columns", "rows", "caption", "totalRows", "evidenceIds"],
2202
+ t
2203
+ );
2204
+ const i = $n(o.columns, `${r}.columns`, t), c = b(
2205
+ o.title,
2206
+ `${r}.title`,
2207
+ u.contentTitle,
2208
+ t
2209
+ ), l = b(
2210
+ o.id,
2211
+ `${r}.id`,
2212
+ u.id,
2213
+ t
2214
+ ), d = b(
2215
+ o.caption,
2216
+ `${r}.caption`,
2217
+ u.contentItem,
2218
+ t
2219
+ ), m = hn(
2220
+ o.totalRows,
2221
+ `${r}.totalRows`,
2222
+ t
2223
+ ), p = A(o.evidenceIds, `${r}.evidenceIds`, t);
2224
+ return {
2225
+ type: "table",
2226
+ ...l ? { id: l } : {},
2227
+ ...c ? { title: c } : {},
2228
+ columns: i,
2229
+ rows: Cn(o.rows, `${r}.rows`, i, t),
2230
+ ...d ? { caption: d } : {},
2231
+ ...m !== void 0 ? { totalRows: m } : {},
2232
+ ...p ? { evidenceIds: p } : {}
2233
+ };
2234
+ }
2235
+ if (a === "evidence_appendix") {
2236
+ y(o, r, ["type", "title", "evidenceIds"], t);
2237
+ const i = b(
2238
+ o.title,
2239
+ `${r}.title`,
2240
+ u.contentTitle,
2241
+ t
2242
+ );
2243
+ return {
2244
+ type: "evidence_appendix",
2245
+ ...i ? { title: i } : {},
2246
+ evidenceIds: A(o.evidenceIds, `${r}.evidenceIds`, t, {
2247
+ required: !0
2248
+ }) ?? []
2249
+ };
2250
+ }
2251
+ if (a === "sql") {
2252
+ y(o, r, ["type", "title", "sql", "evidenceIds"], t);
2253
+ const i = b(
2254
+ o.title,
2255
+ `${r}.title`,
2256
+ u.contentTitle,
2257
+ t
2258
+ ), c = v(
2259
+ o.sql,
2260
+ `${r}.sql`,
2261
+ u.contentSql,
2262
+ t
2263
+ ), l = A(o.evidenceIds, `${r}.evidenceIds`, t);
2264
+ return {
2265
+ type: "sql",
2266
+ ...i ? { title: i } : {},
2267
+ sql: c,
2268
+ ...l ? { evidenceIds: l } : {}
2269
+ };
2270
+ }
2271
+ return s(
2272
+ t,
2273
+ `${r}.type`,
2274
+ "Expected heading, paragraph, finding, bullets, metric, kpi_grid, progress, table, actions, limitations, sql, or evidence_appendix."
2275
+ ), {
2276
+ type: "paragraph",
2277
+ text: ""
2278
+ };
2279
+ }
2280
+ function En(e) {
2281
+ const n = [], t = $(e, "content", n);
2282
+ y(t, "content", ["version", "title", "summary", "blocks"], n), t.version !== 1 && s(n, "content.version", "Expected version 1.");
2283
+ const r = b(
2284
+ t.title,
2285
+ "content.title",
2286
+ u.contentTitle,
2287
+ n
2288
+ ), o = b(
2289
+ t.summary,
2290
+ "content.summary",
2291
+ u.contentSummary,
2292
+ n
2293
+ );
2294
+ Array.isArray(t.blocks) || s(n, "content.blocks", "Expected an array.");
2295
+ const a = Array.isArray(t.blocks) ? t.blocks : [];
2296
+ a.length === 0 && s(n, "content.blocks", "Expected at least one block."), a.length > S.maxBlocks && s(
2297
+ n,
2298
+ "content.blocks",
2299
+ `Must have ${S.maxBlocks} blocks or fewer.`
2300
+ );
2301
+ const i = a.slice(0, S.maxBlocks).map((c, l) => Tn(c, l, n));
2302
+ return le(n), {
2303
+ version: 1,
2304
+ ...r ? { title: r } : {},
2305
+ ...o ? { summary: o } : {},
2306
+ blocks: i
2307
+ };
2308
+ }
2309
+ function kr(e) {
2310
+ try {
2311
+ return {
2312
+ valid: !0,
2313
+ value: En(e),
2314
+ issues: []
2315
+ };
2316
+ } catch (n) {
2317
+ if (n instanceof W)
2318
+ return { valid: !1, issues: n.issues };
2319
+ throw n;
2320
+ }
2321
+ }
2322
+ function V(e, n, t, r) {
2323
+ return typeof e == "string" && t.includes(e) ? e : (s(r, n, `Expected ${t.join(" or ")}.`), t[0]);
2324
+ }
2325
+ function R(e, n, t, r, o) {
2326
+ if (e != null) {
2327
+ if (typeof e == "string" && t.has(e))
2328
+ return e;
2329
+ s(o, n, `Expected ${r}.`);
2330
+ }
2331
+ }
2332
+ function xn(e, n, t) {
2333
+ if (e != null) {
2334
+ if (!Array.isArray(e)) {
2335
+ s(t, n, "Expected an array.");
2336
+ return;
2337
+ }
2338
+ return e;
2339
+ }
2340
+ }
2341
+ function Sn(e, n, t) {
2342
+ if (e != null) {
2343
+ if (!Fe(e)) {
2344
+ s(t, n, "Expected an object.");
2345
+ return;
2346
+ }
2347
+ return e;
2348
+ }
2349
+ }
2350
+ function kn(e, n, t) {
2351
+ if (e == null)
2352
+ return;
2353
+ const r = $(e, n, t);
2354
+ y(r, n, fn, t);
2355
+ const o = {};
2356
+ if (r.matrix !== void 0) {
2357
+ const m = $(r.matrix, `${n}.matrix`, t);
2358
+ y(m, `${n}.matrix`, ["config", "content"], t);
2359
+ const p = We.safeParse(m.config);
2360
+ p.success || s(t, `${n}.matrix.config`, "Expected a valid Matrix definition.");
2361
+ const f = R(
2362
+ m.content,
2363
+ `${n}.matrix.content`,
2364
+ /* @__PURE__ */ new Set(["current", "all", "flat"]),
2365
+ "current, all, or flat",
2366
+ t
2367
+ );
2368
+ f || s(t, `${n}.matrix.content`, "Choose Matrix export content."), p.success && f && (o.matrix = { config: p.data, content: f });
2369
+ }
2370
+ const a = R(
2371
+ r.pageSize,
2372
+ `${n}.pageSize`,
2373
+ rn,
2374
+ "letter, legal, a4, a3, or tabloid",
2375
+ t
2376
+ ), i = R(
2377
+ r.orientation,
2378
+ `${n}.orientation`,
2379
+ on,
2380
+ "portrait or landscape",
2381
+ t
2382
+ ), c = R(
2383
+ r.delimiter,
2384
+ `${n}.delimiter`,
2385
+ an,
2386
+ "comma, semicolon, or tab",
2387
+ t
2388
+ ), l = R(
2389
+ r.csvEncoding,
2390
+ `${n}.csvEncoding`,
2391
+ cn,
2392
+ "utf-8-bom or utf-8",
2393
+ t
2394
+ ), d = R(
2395
+ r.sheetSelection,
2396
+ `${n}.sheetSelection`,
2397
+ ln,
2398
+ "current or all",
2399
+ t
2400
+ );
2401
+ a && (o.pageSize = a), i && (o.orientation = i), c && (o.delimiter = c), l && (o.csvEncoding = l), d && (o.sheetSelection = d);
2402
+ for (const m of [
2403
+ "includeFilters",
2404
+ "includeTimestamp",
2405
+ "includeHeaders",
2406
+ "useFormattedValues",
2407
+ "allowDownload"
2408
+ ])
2409
+ if (!(r[m] === void 0 || r[m] === null)) {
2410
+ if (typeof r[m] != "boolean") {
2411
+ s(t, `${n}.${m}`, "Expected a boolean.");
2412
+ continue;
2413
+ }
2414
+ o[m] = r[m];
2415
+ }
2416
+ for (const m of [
2417
+ "currentSheetId",
2418
+ "currentSheetName",
2419
+ "selectedSheetId",
2420
+ "cardType",
2421
+ "theme"
2422
+ ]) {
2423
+ const p = b(
2424
+ r[m],
2425
+ `${n}.${m}`,
2426
+ u.id,
2427
+ t
2428
+ );
2429
+ p && (o[m] = p);
2430
+ }
2431
+ for (const m of [
2432
+ "filterValues",
2433
+ "inlineFilterValues",
2434
+ "sheetFilterValues",
2435
+ "controlDefinitions",
2436
+ "cardControlDefinitions",
2437
+ "controlBindings"
2438
+ ]) {
2439
+ const p = xn(r[m], `${n}.${m}`, t);
2440
+ p && (o[m] = p);
2441
+ }
2442
+ for (const m of [
2443
+ "controlValues",
2444
+ "tablePreferences",
2445
+ "dashboardInputExecutionSnapshot",
2446
+ "printInputCapture"
2447
+ ]) {
2448
+ const p = Sn(r[m], `${n}.${m}`, t);
2449
+ p && (o[m] = p);
2450
+ }
2451
+ return Object.keys(o).length > 0 ? o : void 0;
2452
+ }
2453
+ function J(e, n, t, r) {
2454
+ const o = b(
2455
+ n,
2456
+ t,
2457
+ u.attachmentTitle,
2458
+ r
2459
+ );
2460
+ return o && (e.title = o), e;
2461
+ }
2462
+ function ee(e, n, t, r) {
2463
+ const o = kn(n, t, r);
2464
+ return o != null && o.printInputCapture && e.type !== "dashboard" && s(
2465
+ r,
2466
+ `${t}.printInputCapture`,
2467
+ "Only a full dashboard attachment can carry printInputCapture."
2468
+ ), o && (e.settings = o), e;
2469
+ }
2470
+ function _n(e, n, t) {
2471
+ const r = `attachments.${n}`, o = $(e, r, t), a = o.type;
2472
+ if (a === "dashboard") {
2473
+ y(
2474
+ o,
2475
+ r,
2476
+ ["type", "dashboardId", "format", "title", "settings"],
2477
+ t
2478
+ );
2479
+ const i = J(
2480
+ {
2481
+ type: "dashboard",
2482
+ dashboardId: v(
2483
+ o.dashboardId,
2484
+ `${r}.dashboardId`,
2485
+ u.id,
2486
+ t
2487
+ ),
2488
+ format: V(o.format, `${r}.format`, ["pdf"], t)
2489
+ },
2490
+ o.title,
2491
+ `${r}.title`,
2492
+ t
2493
+ );
2494
+ return ee(i, o.settings, `${r}.settings`, t);
2495
+ }
2496
+ if (a === "dashboard_sheet" || a === "document_sheet") {
2497
+ y(
2498
+ o,
2499
+ r,
2500
+ ["type", "dashboardId", "sheetId", "format", "title", "settings"],
2501
+ t
2502
+ );
2503
+ const i = J(
2504
+ {
2505
+ type: a,
2506
+ dashboardId: v(
2507
+ o.dashboardId,
2508
+ `${r}.dashboardId`,
2509
+ u.id,
2510
+ t
2511
+ ),
2512
+ sheetId: v(
2513
+ o.sheetId,
2514
+ `${r}.sheetId`,
2515
+ u.id,
2516
+ t
2517
+ ),
2518
+ format: V(o.format, `${r}.format`, ["pdf"], t)
2519
+ },
2520
+ o.title,
2521
+ `${r}.title`,
2522
+ t
2523
+ );
2524
+ return ee(i, o.settings, `${r}.settings`, t);
2525
+ }
2526
+ if (a === "card") {
2527
+ y(
2528
+ o,
2529
+ r,
2530
+ ["type", "dashboardId", "cardId", "format", "title", "settings"],
2531
+ t
2532
+ );
2533
+ const i = J(
2534
+ {
2535
+ type: "card",
2536
+ dashboardId: v(
2537
+ o.dashboardId,
2538
+ `${r}.dashboardId`,
2539
+ u.id,
2540
+ t
2541
+ ),
2542
+ cardId: v(
2543
+ o.cardId,
2544
+ `${r}.cardId`,
2545
+ u.id,
2546
+ t
2547
+ ),
2548
+ format: V(
2549
+ o.format,
2550
+ `${r}.format`,
2551
+ ["csv", "pdf"],
2552
+ t
2553
+ )
2554
+ },
2555
+ o.title,
2556
+ `${r}.title`,
2557
+ t
2558
+ );
2559
+ return ee(i, o.settings, `${r}.settings`, t);
2560
+ }
2561
+ return s(
2562
+ t,
2563
+ `${r}.type`,
2564
+ "Expected dashboard, dashboard_sheet, document_sheet, or card."
2565
+ ), { type: "dashboard", dashboardId: "", format: "pdf" };
2566
+ }
2567
+ function An(e) {
2568
+ switch (e.type) {
2569
+ case "dashboard":
2570
+ return `${e.type}:${e.dashboardId}:${e.format}`;
2571
+ case "dashboard_sheet":
2572
+ case "document_sheet":
2573
+ return `${e.type}:${e.dashboardId}:${e.sheetId}:${e.format}`;
2574
+ case "card":
2575
+ return `${e.type}:${e.dashboardId}:${e.cardId}:${e.format}`;
2576
+ }
2577
+ }
2578
+ function Be(e, n) {
2579
+ if (e == null)
2580
+ return [];
2581
+ if (!Array.isArray(e))
2582
+ return s(n, "attachments", "Expected an array."), [];
2583
+ e.length > X && s(
2584
+ n,
2585
+ "attachments",
2586
+ `Choose ${X} attachments or fewer.`
2587
+ );
2588
+ const t = e.slice(0, X).map((o, a) => _n(o, a, n)), r = /* @__PURE__ */ new Set();
2589
+ return t.forEach((o, a) => {
2590
+ var c;
2591
+ (c = o.settings) != null && c.matrix && (o.type !== "card" || o.settings.cardType !== "matrixTable" || o.settings.matrix.content === "flat" && o.format !== "csv") && s(n, `attachments.${a}.settings.matrix`, "Matrix settings require a matrixTable card attachment; flat content requires CSV.");
2592
+ const i = An(o);
2593
+ r.has(i) && s(n, `attachments.${a}`, "Duplicate attachment."), r.add(i);
2594
+ }), t;
2595
+ }
2596
+ function Ne(e, n) {
2597
+ if (e == null)
2598
+ return;
2599
+ const t = $(e, "limits", n);
2600
+ y(t, "limits", Object.keys(Y), n);
2601
+ const r = {};
2602
+ return Object.keys(Y).forEach((o) => {
2603
+ const a = t[o];
2604
+ if (a == null)
2605
+ return;
2606
+ const i = Y[o];
2607
+ if (typeof a != "number" || !Number.isInteger(a) || a < i.min || a > i.max) {
2608
+ s(
2609
+ n,
2610
+ `limits.${o}`,
2611
+ `Expected an integer between ${i.min} and ${i.max}.`
2612
+ );
2613
+ return;
2614
+ }
2615
+ r[o] = a;
2616
+ }), Object.keys(r).length > 0 ? r : void 0;
2617
+ }
2618
+ function le(e) {
2619
+ if (e.length > 0)
2620
+ throw new W(e);
2621
+ }
2622
+ function Pe(e, n, t) {
2623
+ !(e.type === "generated_analysis" || e.type === "custom_message" && !!e.message.trim()) && n.length === 0 && s(
2624
+ t,
2625
+ "body",
2626
+ "Add briefing instructions, a custom message, or at least one attachment."
2627
+ );
2628
+ }
2629
+ function Fn(e, n, t) {
2630
+ e == null || e.forEach((r, o) => {
2631
+ const a = `${t}.${o}.scope`, i = r.scope.attachmentIndex;
2632
+ if (i === void 0)
2633
+ throw new L(
2634
+ `${a}.attachmentIndex must identify the attachment that owns this presentation entry.`
2635
+ );
2636
+ const c = n[i];
2637
+ if (!c)
2638
+ throw new L(
2639
+ `${a}.attachmentIndex must identify an existing attachment.`
2640
+ );
2641
+ if (r.scope.dashboardId !== c.dashboardId)
2642
+ throw new L(
2643
+ `${a}.dashboardId must match the dashboard selected by the referenced attachment.`
2644
+ );
2645
+ if (c.type === "card" && r.scope.cardId !== c.cardId)
2646
+ throw new L(
2647
+ `${a}.cardId must match the card selected by the referenced attachment.`
2648
+ );
2649
+ });
2650
+ }
2651
+ function Le(e) {
2652
+ const n = [], t = $(e, "jobConfig", n);
2653
+ y(
2654
+ t,
2655
+ "jobConfig",
2656
+ [
2657
+ "kind",
2658
+ "presentationExecutionSnapshot",
2659
+ "source",
2660
+ "body",
2661
+ "attachments",
2662
+ "presentation",
2663
+ "limits"
2664
+ ],
2665
+ n
2666
+ ), t.kind !== ne && s(n, "kind", "Expected BRIEFING.");
2667
+ let r;
2668
+ try {
2669
+ r = Je(
2670
+ t.presentationExecutionSnapshot
2671
+ );
2672
+ } catch (d) {
2673
+ if (d instanceof L)
2674
+ throw d;
2675
+ s(
2676
+ n,
2677
+ "jobConfig.presentationExecutionSnapshot",
2678
+ d instanceof Error ? d.message : "Invalid presentation snapshot."
2679
+ );
2680
+ }
2681
+ const o = De(t.source, n), a = Re(t.body, n), i = Be(t.attachments, n), c = Oe(t.presentation, n), l = Ne(t.limits, n);
2682
+ return Pe(a, i, n), Fn(
2683
+ r == null ? void 0 : r.resolvedFormats,
2684
+ i,
2685
+ "jobConfig.presentationExecutionSnapshot.resolvedFormats"
2686
+ ), le(n), {
2687
+ kind: ne,
2688
+ presentationExecutionSnapshot: r,
2689
+ source: o,
2690
+ body: a,
2691
+ attachments: i,
2692
+ presentation: c,
2693
+ ...l ? { limits: l } : {}
2694
+ };
2695
+ }
2696
+ function _r(e) {
2697
+ return Le({
2698
+ ...e,
2699
+ kind: ne
2700
+ });
2701
+ }
2702
+ function de(e, n, t, r = "deliveryConfig.recipients") {
2703
+ const o = `${r}.${n}`, a = $(e, o, t), i = a.type;
2704
+ if (i === "email") {
2705
+ y(a, o, ["type", "address", "name"], t);
2706
+ const c = v(
2707
+ a.address,
2708
+ `${o}.address`,
2709
+ u.id,
2710
+ t
2711
+ ), l = b(
2712
+ a.name,
2713
+ `${o}.name`,
2714
+ u.attachmentTitle,
2715
+ t
2716
+ );
2717
+ return c && !gn(c) && s(t, `${o}.address`, "Email address is invalid."), {
2718
+ type: "email",
2719
+ address: c,
2720
+ ...l ? { name: l } : {}
2721
+ };
2722
+ }
2723
+ return i === "user" ? (y(a, o, ["type", "userId"], t), {
2724
+ type: "user",
2725
+ userId: v(
2726
+ a.userId,
2727
+ `${o}.userId`,
2728
+ u.id,
2729
+ t
2730
+ )
2731
+ }) : i === "tenant_user" ? (y(a, o, ["type", "tenantUserId"], t), {
2732
+ type: "tenant_user",
2733
+ tenantUserId: v(
2734
+ a.tenantUserId,
2735
+ `${o}.tenantUserId`,
2736
+ u.id,
2737
+ t
2738
+ )
2739
+ }) : i === "group" ? (y(a, o, ["type", "groupId"], t), {
2740
+ type: "group",
2741
+ groupId: v(
2742
+ a.groupId,
2743
+ `${o}.groupId`,
2744
+ u.id,
2745
+ t
2746
+ )
2747
+ }) : (s(
2748
+ t,
2749
+ `${o}.type`,
2750
+ "Expected email, user, tenant_user, or group."
2751
+ ), { type: "email", address: "" });
2752
+ }
2753
+ function Dn(e, n) {
2754
+ return e == null ? [] : Array.isArray(e) ? e.map(
2755
+ (t, r) => de(t, r, n)
2756
+ ) : (s(n, "deliveryConfig.recipients", "Expected an array."), []);
2757
+ }
2758
+ function Rn(e, n) {
2759
+ if (!Array.isArray(e))
2760
+ return s(n, "deliveryConfig.channels", "Expected an array."), [];
2761
+ const t = [];
2762
+ return e.forEach((r, o) => {
2763
+ if (!ze(r)) {
2764
+ s(
2765
+ n,
2766
+ `deliveryConfig.channels.${o}`,
2767
+ "Expected EMAIL, WEBHOOK, SLACK, IN_APP, or TELEGRAM."
2768
+ );
2769
+ return;
2770
+ }
2771
+ t.includes(r) || t.push(r);
2772
+ }), t;
2773
+ }
2774
+ function On(e, n, t) {
2775
+ if (e == null)
2776
+ return;
2777
+ const r = $(e, n, t), o = {};
2778
+ return Object.entries(r).forEach(([a, i]) => {
2779
+ if (typeof i != "string") {
2780
+ s(t, `${n}.${a}`, "Expected a string.");
2781
+ return;
2782
+ }
2783
+ o[a] = i.trim();
2784
+ }), Object.keys(o).length > 0 ? o : void 0;
2785
+ }
2786
+ function Mn(e, n, t) {
2787
+ if (e == null)
2788
+ return;
2789
+ const r = $(e, n, t);
2790
+ y(
2791
+ r,
2792
+ n,
2793
+ ["url", "method", "headers", "secretEncrypted"],
2794
+ t
2795
+ );
2796
+ const o = r.method === void 0 || r.method === null ? void 0 : V(r.method, `${n}.method`, ["POST", "PUT"], t), a = On(r.headers, `${n}.headers`, t), i = b(
2797
+ r.secretEncrypted,
2798
+ `${n}.secretEncrypted`,
2799
+ 2e3,
2800
+ t
2801
+ );
2802
+ return {
2803
+ url: v(r.url, `${n}.url`, 2e3, t),
2804
+ ...o ? { method: o } : {},
2805
+ ...a ? { headers: a } : {},
2806
+ ...i ? { secretEncrypted: i } : {}
2807
+ };
2808
+ }
2809
+ function Bn(e, n, t) {
2810
+ const r = $(e, n, t), o = r.type;
2811
+ if (o === "channel") {
2812
+ y(
2813
+ r,
2814
+ n,
2815
+ ["type", "channelId", "channelName", "isPrivate"],
2816
+ t
2817
+ );
2818
+ const a = b(
2819
+ r.channelName,
2820
+ `${n}.channelName`,
2821
+ u.attachmentTitle,
2822
+ t
2823
+ ), i = r.isPrivate === void 0 || r.isPrivate === null ? void 0 : N(
2824
+ r.isPrivate,
2825
+ !1,
2826
+ `${n}.isPrivate`,
2827
+ t
2828
+ );
2829
+ return {
2830
+ type: "channel",
2831
+ channelId: v(
2832
+ r.channelId,
2833
+ `${n}.channelId`,
2834
+ u.id,
2835
+ t
2836
+ ),
2837
+ ...a ? { channelName: a } : {},
2838
+ ...i !== void 0 ? { isPrivate: i } : {}
2839
+ };
2840
+ }
2841
+ return o === "dm" ? (y(r, n, ["type", "recipient"], t), s(
2842
+ t,
2843
+ `${n}.type`,
2844
+ "Slack DM delivery is not supported in V1."
2845
+ ), {
2846
+ type: "dm",
2847
+ recipient: de(r.recipient, 0, t, `${n}.recipient`)
2848
+ }) : (s(t, `${n}.type`, "Expected channel."), { type: "channel", channelId: "" });
2849
+ }
2850
+ function Nn(e, n, t) {
2851
+ if (e == null)
2852
+ return;
2853
+ if (!Array.isArray(e)) {
2854
+ s(t, n, "Expected an array.");
2855
+ return;
2856
+ }
2857
+ const r = e.map(
2858
+ (o, a) => de(o, a, t, n)
2859
+ );
2860
+ return r.length > 0 ? r : void 0;
2861
+ }
2862
+ function Pn(e, n, t) {
2863
+ if (e == null)
2864
+ return;
2865
+ const r = $(e, n, t);
2866
+ y(
2867
+ r,
2868
+ n,
2869
+ [
2870
+ "destination",
2871
+ "threadMentions",
2872
+ "postThreadDetail",
2873
+ "includeDashboardLink",
2874
+ "includeBriefingLink"
2875
+ ],
2876
+ t
2877
+ );
2878
+ const o = Nn(
2879
+ r.threadMentions,
2880
+ `${n}.threadMentions`,
2881
+ t
2882
+ ), a = N(
2883
+ r.postThreadDetail,
2884
+ !0,
2885
+ `${n}.postThreadDetail`,
2886
+ t
2887
+ ), i = N(
2888
+ r.includeDashboardLink,
2889
+ !0,
2890
+ `${n}.includeDashboardLink`,
2891
+ t
2892
+ ), c = N(
2893
+ r.includeBriefingLink,
2894
+ !0,
2895
+ `${n}.includeBriefingLink`,
2896
+ t
2897
+ );
2898
+ return {
2899
+ destination: Bn(
2900
+ r.destination,
2901
+ `${n}.destination`,
2902
+ t
2903
+ ),
2904
+ ...o ? { threadMentions: o } : {},
2905
+ ...r.postThreadDetail !== void 0 ? { postThreadDetail: a } : {},
2906
+ ...r.includeDashboardLink !== void 0 ? { includeDashboardLink: i } : {},
2907
+ ...r.includeBriefingLink !== void 0 ? { includeBriefingLink: c } : {}
2908
+ };
2909
+ }
2910
+ function Ln(e, n, t) {
2911
+ const r = $(e, n, t);
2912
+ y(
2913
+ r,
2914
+ n,
2915
+ [
2916
+ "subjectOverride",
2917
+ "titleOverride",
2918
+ "summaryOverride",
2919
+ "actionBlockVisible",
2920
+ "formatProfile",
2921
+ "slackConfig",
2922
+ "webhookConfig"
2923
+ ],
2924
+ t
2925
+ );
2926
+ const o = R(
2927
+ r.formatProfile,
2928
+ `${n}.formatProfile`,
2929
+ dn,
2930
+ "concise, balanced, or detailed",
2931
+ t
2932
+ ), a = b(
2933
+ r.subjectOverride,
2934
+ `${n}.subjectOverride`,
2935
+ 500,
2936
+ t
2937
+ ), i = b(
2938
+ r.titleOverride,
2939
+ `${n}.titleOverride`,
2940
+ 500,
2941
+ t
2942
+ ), c = b(
2943
+ r.summaryOverride,
2944
+ `${n}.summaryOverride`,
2945
+ 2e3,
2946
+ t
2947
+ ), l = N(
2948
+ r.actionBlockVisible,
2949
+ !0,
2950
+ `${n}.actionBlockVisible`,
2951
+ t
2952
+ ), d = Mn(
2953
+ r.webhookConfig,
2954
+ `${n}.webhookConfig`,
2955
+ t
2956
+ ), m = Pn(
2957
+ r.slackConfig,
2958
+ `${n}.slackConfig`,
2959
+ t
2960
+ );
2961
+ return {
2962
+ ...o ? { formatProfile: o } : {},
2963
+ ...a ? { subjectOverride: a } : {},
2964
+ ...i ? { titleOverride: i } : {},
2965
+ ...c ? { summaryOverride: c } : {},
2966
+ ...r.actionBlockVisible !== void 0 ? { actionBlockVisible: l } : {},
2967
+ ...m ? { slackConfig: m } : {},
2968
+ ...d ? { webhookConfig: d } : {}
2969
+ };
2970
+ }
2971
+ function zn(e, n) {
2972
+ if (e == null)
2973
+ return;
2974
+ const t = $(e, "deliveryConfig.channelConfigs", n), r = {};
2975
+ return Object.entries(t).forEach(([o, a]) => {
2976
+ if (!ze(o)) {
2977
+ s(
2978
+ n,
2979
+ `deliveryConfig.channelConfigs.${o}`,
2980
+ "Expected a supported delivery channel."
2981
+ );
2982
+ return;
2983
+ }
2984
+ r[o] = Ln(
2985
+ a,
2986
+ `deliveryConfig.channelConfigs.${o}`,
2987
+ n
2988
+ );
2989
+ }), Object.keys(r).length > 0 ? r : void 0;
2990
+ }
2991
+ function Kn(e, n) {
2992
+ var l, d, m;
2993
+ if (e == null)
2994
+ return null;
2995
+ const t = $(e, "deliveryConfig", n);
2996
+ y(
2997
+ t,
2998
+ "deliveryConfig",
2999
+ ["recipients", "channels", "channelConfigs"],
3000
+ n
3001
+ );
3002
+ const r = zn(t.channelConfigs, n), o = Dn(t.recipients, n), a = Rn(t.channels, n), i = ((d = (l = r == null ? void 0 : r.SLACK) == null ? void 0 : l.slackConfig) == null ? void 0 : d.destination.type) === "channel" && !!r.SLACK.slackConfig.destination.channelId.trim();
3003
+ return a.some(
3004
+ (p) => p !== "SLACK"
3005
+ ) && o.length === 0 && s(
3006
+ n,
3007
+ "deliveryConfig.recipients",
3008
+ "Add at least one recipient or remove delivery config."
3009
+ ), a.length === 0 && s(
3010
+ n,
3011
+ "deliveryConfig.channels",
3012
+ "Choose at least one delivery channel or remove delivery config."
3013
+ ), a.includes("SLACK") && !i && s(
3014
+ n,
3015
+ "deliveryConfig.channelConfigs.SLACK.slackConfig.destination.channelId",
3016
+ "Choose a Slack channel destination."
3017
+ ), !a.includes("SLACK") && ((m = r == null ? void 0 : r.SLACK) != null && m.slackConfig) && s(
3018
+ n,
3019
+ "deliveryConfig.channelConfigs.SLACK",
3020
+ "Slack config requires SLACK in deliveryConfig.channels."
3021
+ ), {
3022
+ recipients: o,
3023
+ channels: a,
3024
+ ...r ? { channelConfigs: r } : {}
3025
+ };
3026
+ }
3027
+ function se(e) {
3028
+ const n = [], t = $(e, "draft", n);
3029
+ y(
3030
+ t,
3031
+ "draft",
3032
+ [
3033
+ "name",
3034
+ "description",
3035
+ "status",
3036
+ "scheduleExpr",
3037
+ "timezone",
3038
+ "source",
3039
+ "body",
3040
+ "attachments",
3041
+ "presentation",
3042
+ "limits",
3043
+ "deliveryConfig"
3044
+ ],
3045
+ n
3046
+ );
3047
+ const r = v(
3048
+ t.name,
3049
+ "name",
3050
+ u.name,
3051
+ n
3052
+ ), o = b(
3053
+ t.description,
3054
+ "description",
3055
+ u.description,
3056
+ n
3057
+ ) ?? null, a = b(t.scheduleExpr, "scheduleExpr", 500, n) ?? null, i = b(t.timezone, "timezone", 200, n) ?? "UTC", c = yn(t.status, n), l = De(t.source, n), d = Re(t.body, n), m = Be(t.attachments, n), p = Oe(t.presentation, n), f = Ne(t.limits, n), h = Kn(t.deliveryConfig, n);
3058
+ return Pe(d, m, n), le(n), {
3059
+ name: r,
3060
+ description: o,
3061
+ status: c,
3062
+ scheduleExpr: a,
3063
+ timezone: i,
3064
+ source: l,
3065
+ body: d,
3066
+ attachments: m,
3067
+ presentation: p,
3068
+ ...f ? { limits: f } : {},
3069
+ deliveryConfig: h
3070
+ };
3071
+ }
3072
+ function Ar(e) {
3073
+ return se(e);
3074
+ }
3075
+ function Fr(e) {
3076
+ return se(e);
3077
+ }
3078
+ function Dr(e) {
3079
+ try {
3080
+ return { valid: !0, value: se(e), issues: [] };
3081
+ } catch (n) {
3082
+ if (n instanceof W)
3083
+ return { valid: !1, issues: n.issues };
3084
+ throw n;
3085
+ }
3086
+ }
3087
+ function Rr(e) {
3088
+ try {
3089
+ return { valid: !0, value: Le(e), issues: [] };
3090
+ } catch (n) {
3091
+ if (n instanceof W)
3092
+ return { valid: !1, issues: n.issues };
3093
+ throw n;
3094
+ }
3095
+ }
3096
+ function Or(e) {
3097
+ return typeof e == "string" && Ae.has(e);
3098
+ }
3099
+ function ze(e) {
3100
+ return typeof e == "string" && nn.has(e);
3101
+ }
3102
+ export {
3103
+ Dr as $,
3104
+ xe as A,
3105
+ Xt as B,
3106
+ Tr as C,
3107
+ br as D,
3108
+ xt as E,
3109
+ Ct as F,
3110
+ ve as G,
3111
+ sr as H,
3112
+ dr as I,
3113
+ ne as J,
3114
+ Jt as K,
3115
+ re as L,
3116
+ X as M,
3117
+ u as N,
3118
+ S as O,
3119
+ en as P,
3120
+ tn as Q,
3121
+ T as R,
3122
+ Sr as S,
3123
+ W as T,
3124
+ En as U,
3125
+ kr as V,
3126
+ Le as W,
3127
+ _r as X,
3128
+ se as Y,
3129
+ Ar as Z,
3130
+ Fr as _,
3131
+ Er as a,
3132
+ Rr as a0,
3133
+ Or as a1,
3134
+ ze as a2,
3135
+ cr as a3,
3136
+ $t as a4,
3137
+ wt as a5,
3138
+ Yt as a6,
3139
+ It as b,
3140
+ ir as c,
3141
+ wr as d,
3142
+ lr as e,
3143
+ vr as f,
3144
+ xr as g,
3145
+ kt as h,
3146
+ gr as i,
3147
+ ie as j,
3148
+ hr as k,
3149
+ mr as l,
3150
+ fr as m,
3151
+ we as n,
3152
+ pr as o,
3153
+ yr as p,
3154
+ ar as q,
3155
+ _t as r,
3156
+ Pt as s,
3157
+ ke as t,
3158
+ Ir as u,
3159
+ ur as v,
3160
+ P as w,
3161
+ $r as x,
3162
+ Wt as y,
3163
+ Cr as z
3164
+ };