@magemetrics/core 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ var addApiKeyHeader = (apiKey) => {
57
57
 
58
58
  // package.json
59
59
  var package_default = {
60
- version: "0.8.1"};
60
+ version: "0.9.0"};
61
61
 
62
62
  // src/core/MageMetricsEventEmitter.ts
63
63
  var MageMetricsEventEmitter = class {
@@ -151,7 +151,7 @@ var hashString = (value) => {
151
151
  return Array.from(hash).map((b) => b.toString(16).padStart(2, "0")).join("");
152
152
  };
153
153
 
154
- // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.1.0_zod@4.2.1/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
154
+ // ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.1.0_zod@4.3.5/node_modules/@asteasolutions/zod-to-openapi/dist/index.mjs
155
155
  function __rest(s, e) {
156
156
  var t = {};
157
157
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -469,7 +469,7 @@ function getOpenApiConfiguration(refOrOpenapi, metadataOrOptions, options) {
469
469
  };
470
470
  }
471
471
 
472
- // ../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/router/reg-exp-router/node.js
472
+ // ../../node_modules/.pnpm/hono@4.11.4/node_modules/hono/dist/router/reg-exp-router/node.js
473
473
  new Set(".\\+*[^]$()");
474
474
  var createRoute = (routeConfig) => {
475
475
  const route = {
@@ -839,131 +839,6 @@ var ExternalAuthProvider = class {
839
839
  }
840
840
  }
841
841
  };
842
-
843
- // ../shared/dist/src/endpoints/admin-console/sqlPreview.routes.js
844
- var TanStackColumnSchema = z.object({
845
- id: z.string(),
846
- accessorKey: z.string(),
847
- header: z.string(),
848
- cell: z.any().optional(),
849
- meta: z.record(z.string(), z.any()).optional()
850
- });
851
- var SqlPreviewResponseSchema = z.object({
852
- columns: z.array(TanStackColumnSchema),
853
- data: z.array(z.record(z.string(), z.any())),
854
- metadata: z.object({
855
- wasSampled: z.boolean(),
856
- originalCount: z.number(),
857
- sampledCount: z.number()
858
- }).optional()
859
- });
860
- var SqlPreviewErrorSchema = z.object({
861
- error: z.string()
862
- });
863
- createRoute({
864
- method: "post",
865
- path: "/api/v1/admin-console/sql/preview",
866
- operationId: "sqlPreview",
867
- request: {
868
- body: {
869
- content: {
870
- "application/json": {
871
- schema: z.object({
872
- sql: z.string().min(1, "SQL query is required")
873
- })
874
- }
875
- }
876
- }
877
- },
878
- responses: {
879
- 200: {
880
- description: "SQL query executed successfully",
881
- content: {
882
- "application/json": {
883
- schema: SqlPreviewResponseSchema
884
- }
885
- }
886
- },
887
- 400: {
888
- description: "Invalid SQL query or request",
889
- content: {
890
- "application/json": {
891
- schema: SqlPreviewErrorSchema
892
- }
893
- }
894
- },
895
- 500: {
896
- description: "Internal server error",
897
- content: {
898
- "application/json": {
899
- schema: SqlPreviewErrorSchema
900
- }
901
- }
902
- }
903
- }
904
- });
905
-
906
- // ../shared/dist/src/endpoints/utils.js
907
- var limitQueryParams = z.string().pipe(z.coerce.number()).optional().openapi({
908
- param: {
909
- required: false
910
- },
911
- type: "integer"
912
- });
913
- var orderQueryParams = z.string().transform((str) => {
914
- if (!str)
915
- return [];
916
- return str.split(",").map((part) => {
917
- const [column, direction = "ASC"] = part.split(":");
918
- return {
919
- column,
920
- direction: direction.toUpperCase()
921
- };
922
- });
923
- }).pipe(z.array(z.object({
924
- column: z.string(),
925
- direction: z.enum(["ASC", "DESC"])
926
- }))).optional().openapi({
927
- param: {
928
- required: false,
929
- example: "name:asc,date:desc"
930
- },
931
- type: "string"
932
- });
933
- var cursorParams = z.string().pipe(z.coerce.number()).optional().openapi({
934
- param: {
935
- required: false
936
- },
937
- type: "number"
938
- });
939
- var filterQueryParams = z.string().transform((str) => {
940
- if (!str)
941
- return [];
942
- return str.split(",").map((part) => {
943
- const [column, value = ""] = part.split(":").map(decodeURIComponent);
944
- return { column, value };
945
- });
946
- }).pipe(z.array(z.object({
947
- column: z.string(),
948
- value: z.string()
949
- }))).optional().openapi({
950
- param: {
951
- required: false,
952
- example: "status:active,name:John%20Doe"
953
- },
954
- type: "string"
955
- });
956
- var columnsQueryParams = z.string().transform((str) => {
957
- if (!str)
958
- return [];
959
- return str.split(",");
960
- }).optional().openapi({
961
- param: {
962
- required: false,
963
- example: "name,date"
964
- },
965
- type: "string"
966
- });
967
842
  var SupabaseUserHeaderSchema = z.object({
968
843
  [HEADER_SP_TOKEN]: z.string()
969
844
  });
@@ -1151,6 +1026,68 @@ var FrontendReportExplainabilitySchema = ReportExplainabilitySchema.omit({
1151
1026
  sql: z.string().optional()
1152
1027
  });
1153
1028
 
1029
+ // ../shared/dist/src/endpoints/utils.js
1030
+ var limitQueryParams = z.string().pipe(z.coerce.number()).optional().openapi({
1031
+ param: {
1032
+ required: false
1033
+ },
1034
+ type: "integer"
1035
+ });
1036
+ var orderQueryParams = z.string().transform((str) => {
1037
+ if (!str)
1038
+ return [];
1039
+ return str.split(",").map((part) => {
1040
+ const [column, direction = "ASC"] = part.split(":");
1041
+ return {
1042
+ column,
1043
+ direction: direction.toUpperCase()
1044
+ };
1045
+ });
1046
+ }).pipe(z.array(z.object({
1047
+ column: z.string(),
1048
+ direction: z.enum(["ASC", "DESC"])
1049
+ }))).optional().openapi({
1050
+ param: {
1051
+ required: false,
1052
+ example: "name:asc,date:desc"
1053
+ },
1054
+ type: "string"
1055
+ });
1056
+ var cursorParams = z.string().pipe(z.coerce.number()).optional().openapi({
1057
+ param: {
1058
+ required: false
1059
+ },
1060
+ type: "number"
1061
+ });
1062
+ var filterQueryParams = z.string().transform((str) => {
1063
+ if (!str)
1064
+ return [];
1065
+ return str.split(",").map((part) => {
1066
+ const [column, value = ""] = part.split(":").map(decodeURIComponent);
1067
+ return { column, value };
1068
+ });
1069
+ }).pipe(z.array(z.object({
1070
+ column: z.string(),
1071
+ value: z.string()
1072
+ }))).optional().openapi({
1073
+ param: {
1074
+ required: false,
1075
+ example: "status:active,name:John%20Doe"
1076
+ },
1077
+ type: "string"
1078
+ });
1079
+ var columnsQueryParams = z.string().transform((str) => {
1080
+ if (!str)
1081
+ return [];
1082
+ return str.split(",");
1083
+ }).optional().openapi({
1084
+ param: {
1085
+ required: false,
1086
+ example: "name,date"
1087
+ },
1088
+ type: "string"
1089
+ });
1090
+
1154
1091
  // ../shared/dist/src/endpoints/companion/flows.routes.js
1155
1092
  var FlowIdParam = z.object({ flowId: z.uuid() }).openapi("FlowId", { type: "string" });
1156
1093
  var FlowDataIdParam = z.object({ flowDataId: z.string().pipe(z.coerce.number()) }).openapi("FlowDataId", { type: "integer" });
@@ -1852,295 +1789,6 @@ var CreateFlow = createRoute({
1852
1789
  }
1853
1790
  });
1854
1791
 
1855
- // ../shared/dist/src/endpoints/admin-console/contextualInsights.routes.js
1856
- var ExtractInsightResponseSchema = z.object({
1857
- type: z.literal("text"),
1858
- insight: z.string()
1859
- }).or(z.object({
1860
- type: z.literal("missing")
1861
- }));
1862
- createRoute({
1863
- method: "post",
1864
- path: "/api/v1/admin-console/contextual-insights/generate-template",
1865
- operationId: "generateInsightTemplate",
1866
- request: {
1867
- body: {
1868
- content: {
1869
- "application/json": {
1870
- schema: z.object({
1871
- request: z.string(),
1872
- insight_type: z.string(),
1873
- additional_context: z.string().optional()
1874
- })
1875
- }
1876
- }
1877
- }
1878
- },
1879
- responses: {
1880
- 200: {
1881
- description: "Insight template generated successfully",
1882
- content: {
1883
- "application/json": {
1884
- schema: z.object({
1885
- expanded_request: z.string()
1886
- })
1887
- }
1888
- }
1889
- },
1890
- 500: {
1891
- description: "Something wrong happened",
1892
- content: {
1893
- "application/json": {
1894
- schema: z.object({
1895
- error: z.string()
1896
- })
1897
- }
1898
- }
1899
- }
1900
- }
1901
- });
1902
- createRoute({
1903
- method: "get",
1904
- path: "/api/v1/admin-console/contextual-insights/preview/{report_id}/data",
1905
- operationId: "getContextualInsightPreviewData",
1906
- request: {
1907
- params: ReportIdParam,
1908
- query: z.object({
1909
- limit: limitQueryParams,
1910
- order: orderQueryParams,
1911
- cursor: cursorParams,
1912
- filter: filterQueryParams
1913
- })
1914
- },
1915
- responses: {
1916
- 200: {
1917
- description: "The preview data for the contextual insight",
1918
- content: {
1919
- "application/json": {
1920
- schema: SqlPreviewResponseSchema
1921
- }
1922
- }
1923
- },
1924
- 404: {
1925
- content: {
1926
- "application/json": {
1927
- schema: z.object({ error: z.string() })
1928
- }
1929
- },
1930
- description: "Unable to retrieve flow data with this id"
1931
- },
1932
- 500: {
1933
- description: "Something wrong happened",
1934
- content: {
1935
- "application/json": {
1936
- schema: z.object({
1937
- error: z.string()
1938
- })
1939
- }
1940
- }
1941
- }
1942
- }
1943
- });
1944
- createRoute({
1945
- method: "get",
1946
- path: "/api/v1/admin-console/contextual-insights/preview/{report_id}/sample-values",
1947
- operationId: "getContextualInsightColumnSampleValues",
1948
- request: {
1949
- params: ReportIdParam,
1950
- query: z.object({
1951
- column_name: z.string().openapi({
1952
- param: {
1953
- required: true
1954
- },
1955
- type: "string",
1956
- description: "The column name to get sample values for"
1957
- })
1958
- })
1959
- },
1960
- responses: {
1961
- 200: {
1962
- description: "Sample values for the specified column",
1963
- content: {
1964
- "application/json": {
1965
- schema: z.object({
1966
- options: z.array(z.unknown())
1967
- })
1968
- }
1969
- }
1970
- },
1971
- 404: {
1972
- content: {
1973
- "application/json": {
1974
- schema: z.object({ error: z.string() })
1975
- }
1976
- },
1977
- description: "Unable to retrieve flow data with this id"
1978
- },
1979
- 500: {
1980
- description: "Something wrong happened",
1981
- content: {
1982
- "application/json": {
1983
- schema: z.object({
1984
- error: z.string()
1985
- })
1986
- }
1987
- }
1988
- }
1989
- }
1990
- });
1991
- var GenerateInsight = createRoute({
1992
- method: "post",
1993
- path: "/api/v1/contextual-insights/generate-insight",
1994
- operationId: "generateInsight",
1995
- request: {
1996
- body: {
1997
- content: {
1998
- "application/json": {
1999
- schema: z.object({
2000
- selected_filter_value: z.string(),
2001
- custom_id: z.string()
2002
- })
2003
- }
2004
- }
2005
- }
2006
- },
2007
- responses: {
2008
- 200: {
2009
- description: "Insight generated successfully",
2010
- content: {
2011
- "application/json": {
2012
- schema: ExtractInsightResponseSchema
2013
- }
2014
- }
2015
- },
2016
- 404: {
2017
- description: "Insight not found",
2018
- content: {
2019
- "application/json": {
2020
- schema: z.object({
2021
- error: z.string()
2022
- })
2023
- }
2024
- }
2025
- },
2026
- 400: {
2027
- description: "Invalid request",
2028
- content: {
2029
- "application/json": {
2030
- schema: z.object({
2031
- error: z.string()
2032
- })
2033
- }
2034
- }
2035
- },
2036
- 500: {
2037
- description: "Something wrong happened",
2038
- content: {
2039
- "application/json": {
2040
- schema: z.object({
2041
- error: z.string()
2042
- })
2043
- }
2044
- }
2045
- }
2046
- }
2047
- });
2048
- createRoute({
2049
- method: "post",
2050
- path: "/api/v1/admin-console/contextual-insights/extract-insight",
2051
- operationId: "extractInsight",
2052
- request: {
2053
- body: {
2054
- content: {
2055
- "application/json": {
2056
- schema: z.object({
2057
- flow_id: z.string(),
2058
- report_id: z.number(),
2059
- topic: z.string(),
2060
- expanded_request: z.string(),
2061
- insight_type: z.string(),
2062
- selected_filter: z.string(),
2063
- selected_filter_value: z.string(),
2064
- additional_context: z.string().optional()
2065
- })
2066
- }
2067
- }
2068
- }
2069
- },
2070
- responses: {
2071
- 200: {
2072
- description: "Insight extracted successfully",
2073
- content: {
2074
- "application/json": {
2075
- schema: ExtractInsightResponseSchema
2076
- }
2077
- }
2078
- },
2079
- 500: {
2080
- description: "Something wrong happened",
2081
- content: {
2082
- "application/json": {
2083
- schema: z.object({
2084
- error: z.string()
2085
- })
2086
- }
2087
- }
2088
- }
2089
- }
2090
- });
2091
- createRoute({
2092
- method: "post",
2093
- path: "/api/v1/admin-console/contextual-insights/suggest-filter-column",
2094
- operationId: "suggestFilterColumn",
2095
- request: {
2096
- body: {
2097
- content: {
2098
- "application/json": {
2099
- schema: z.object({
2100
- report_id: z.number(),
2101
- request: z.string(),
2102
- insight_type: z.string(),
2103
- additional_context: z.string().optional()
2104
- })
2105
- }
2106
- }
2107
- }
2108
- },
2109
- responses: {
2110
- 200: {
2111
- description: "Filter column suggestion generated successfully",
2112
- content: {
2113
- "application/json": {
2114
- schema: z.object({
2115
- recommended_column: z.string(),
2116
- reasoning: z.string()
2117
- })
2118
- }
2119
- }
2120
- },
2121
- 404: {
2122
- description: "Report not found",
2123
- content: {
2124
- "application/json": {
2125
- schema: z.object({
2126
- error: z.string()
2127
- })
2128
- }
2129
- }
2130
- },
2131
- 500: {
2132
- description: "Something wrong happened",
2133
- content: {
2134
- "application/json": {
2135
- schema: z.object({
2136
- error: z.string()
2137
- })
2138
- }
2139
- }
2140
- }
2141
- }
2142
- });
2143
-
2144
1792
  // ../shared/dist/src/endpoints/companion/speech.routes.js
2145
1793
  var SpeechTokenResponseSchema = z.object({
2146
1794
  token: z.string().describe("Temporary AssemblyAI streaming token"),
@@ -3624,27 +3272,6 @@ var MageMetricsClient = class {
3624
3272
  const filename = contentDisposition ? contentDisposition.split("filename=")[1]?.replace(/"/g, "") || `mm-export-${reportId}.csv` : `mm-export-${reportId}.csv`;
3625
3273
  return { filename, data };
3626
3274
  },
3627
- generateContextualInsight: async (payload) => {
3628
- await this.waitForAuth();
3629
- const { data, error, response } = await this.internalApiClient.POST(
3630
- GenerateInsight.path,
3631
- {
3632
- body: {
3633
- selected_filter_value: payload.selectedFilterValue,
3634
- custom_id: payload.customId
3635
- }
3636
- }
3637
- );
3638
- if (error) {
3639
- throw new ApiError(error.error, response, {
3640
- status: response.status,
3641
- statusText: response.statusText,
3642
- url: response.url,
3643
- method: "POST"
3644
- });
3645
- }
3646
- return data;
3647
- },
3648
3275
  getChatTransport: (flowId, options) => {
3649
3276
  return new MageMetricsChatTransport(this.config.apiUrl, flowId, {
3650
3277
  ...options,