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