@inkindcards/semantic-layer 0.1.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/README.md +3 -0
- package/dist/chunk-4RECQ22F.cjs +131 -0
- package/dist/chunk-4RECQ22F.cjs.map +1 -0
- package/dist/chunk-IQARBGJP.js +128 -0
- package/dist/chunk-IQARBGJP.js.map +1 -0
- package/dist/chunk-NJ4IJBV3.js +121 -0
- package/dist/chunk-NJ4IJBV3.js.map +1 -0
- package/dist/chunk-Y3A3T45C.cjs +127 -0
- package/dist/chunk-Y3A3T45C.cjs.map +1 -0
- package/dist/components.cjs +198 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +36 -0
- package/dist/components.d.ts +36 -0
- package/dist/components.js +195 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +154 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +90 -0
- package/dist/react.d.ts +90 -0
- package/dist/react.js +132 -0
- package/dist/react.js.map +1 -0
- package/dist/types-Ds_6aDEw.d.cts +79 -0
- package/dist/types-Ds_6aDEw.d.ts +79 -0
- package/package.json +50 -0
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4RECQ22F_cjs = require('./chunk-4RECQ22F.cjs');
|
|
4
|
+
var chunkY3A3T45C_cjs = require('./chunk-Y3A3T45C.cjs');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function SemanticLayerProvider({
|
|
9
|
+
gatewayUrl,
|
|
10
|
+
anonKey,
|
|
11
|
+
client: externalClient,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
const client = react.useMemo(() => {
|
|
15
|
+
if (externalClient) return externalClient;
|
|
16
|
+
return new chunk4RECQ22F_cjs.SemanticLayerClient({ gatewayUrl, anonKey });
|
|
17
|
+
}, [gatewayUrl, anonKey, externalClient]);
|
|
18
|
+
const [auth, setAuth] = react.useState({
|
|
19
|
+
isAuthenticated: false,
|
|
20
|
+
isLoading: true,
|
|
21
|
+
user: null,
|
|
22
|
+
error: null
|
|
23
|
+
});
|
|
24
|
+
react.useEffect(() => {
|
|
25
|
+
let mounted = true;
|
|
26
|
+
async function initAuth() {
|
|
27
|
+
try {
|
|
28
|
+
const session = await client.getSession();
|
|
29
|
+
if (!mounted) return;
|
|
30
|
+
if (session?.user) {
|
|
31
|
+
setAuth({
|
|
32
|
+
isAuthenticated: true,
|
|
33
|
+
isLoading: false,
|
|
34
|
+
user: { id: session.user.id, email: session.user.email || "" },
|
|
35
|
+
error: null
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
setAuth({
|
|
39
|
+
isAuthenticated: false,
|
|
40
|
+
isLoading: false,
|
|
41
|
+
user: null,
|
|
42
|
+
error: null
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (!mounted) return;
|
|
47
|
+
setAuth({
|
|
48
|
+
isAuthenticated: false,
|
|
49
|
+
isLoading: false,
|
|
50
|
+
user: null,
|
|
51
|
+
error: err instanceof Error ? err.message : "Auth initialization failed"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
initAuth();
|
|
56
|
+
const { data: { subscription } } = client.onAuthStateChange((_event, session) => {
|
|
57
|
+
if (!mounted) return;
|
|
58
|
+
if (session?.user) {
|
|
59
|
+
setAuth({
|
|
60
|
+
isAuthenticated: true,
|
|
61
|
+
isLoading: false,
|
|
62
|
+
user: { id: session.user.id, email: session.user.email || "" },
|
|
63
|
+
error: null
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
setAuth({
|
|
67
|
+
isAuthenticated: false,
|
|
68
|
+
isLoading: false,
|
|
69
|
+
user: null,
|
|
70
|
+
error: null
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
mounted = false;
|
|
76
|
+
subscription.unsubscribe();
|
|
77
|
+
};
|
|
78
|
+
}, [client]);
|
|
79
|
+
const value = react.useMemo(() => ({ client, auth }), [client, auth]);
|
|
80
|
+
return /* @__PURE__ */ jsxRuntime.jsx(chunkY3A3T45C_cjs.SemanticLayerContext.Provider, { value, children });
|
|
81
|
+
}
|
|
82
|
+
var defaultLoadingStyle = {
|
|
83
|
+
display: "flex",
|
|
84
|
+
alignItems: "center",
|
|
85
|
+
justifyContent: "center",
|
|
86
|
+
minHeight: "100vh",
|
|
87
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
88
|
+
color: "#6b7280"
|
|
89
|
+
};
|
|
90
|
+
var defaultContainerStyle = {
|
|
91
|
+
display: "flex",
|
|
92
|
+
flexDirection: "column",
|
|
93
|
+
alignItems: "center",
|
|
94
|
+
justifyContent: "center",
|
|
95
|
+
minHeight: "100vh",
|
|
96
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
97
|
+
gap: "16px"
|
|
98
|
+
};
|
|
99
|
+
var defaultButtonStyle = {
|
|
100
|
+
padding: "12px 24px",
|
|
101
|
+
fontSize: "16px",
|
|
102
|
+
fontWeight: 500,
|
|
103
|
+
color: "#ffffff",
|
|
104
|
+
backgroundColor: "#4285f4",
|
|
105
|
+
border: "none",
|
|
106
|
+
borderRadius: "8px",
|
|
107
|
+
cursor: "pointer",
|
|
108
|
+
display: "flex",
|
|
109
|
+
alignItems: "center",
|
|
110
|
+
gap: "8px"
|
|
111
|
+
};
|
|
112
|
+
function AuthGate({ children, loading, signInComponent }) {
|
|
113
|
+
const { isAuthenticated, isLoading, error, signIn, user } = chunkY3A3T45C_cjs.useAuth();
|
|
114
|
+
if (isLoading) {
|
|
115
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: loading || /* @__PURE__ */ jsxRuntime.jsx("div", { style: defaultLoadingStyle, children: "Loading..." }) });
|
|
116
|
+
}
|
|
117
|
+
if (!isAuthenticated) {
|
|
118
|
+
if (signInComponent) {
|
|
119
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: signInComponent({ signIn: () => signIn() }) });
|
|
120
|
+
}
|
|
121
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: defaultContainerStyle, children: [
|
|
122
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: { margin: 0, fontSize: "24px", color: "#111827" }, children: "Sign in to continue" }),
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, color: "#6b7280" }, children: "Use your inKind Google account to access data." }),
|
|
124
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, color: "#ef4444", fontSize: "14px" }, children: error }),
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: defaultButtonStyle, onClick: () => signIn(), children: "Sign in with Google" })
|
|
126
|
+
] });
|
|
127
|
+
}
|
|
128
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
Object.defineProperty(exports, "SemanticLayerContext", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () { return chunkY3A3T45C_cjs.SemanticLayerContext; }
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "useAuth", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function () { return chunkY3A3T45C_cjs.useAuth; }
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, "useMetrics", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function () { return chunkY3A3T45C_cjs.useMetrics; }
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, "usePivotQuery", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function () { return chunkY3A3T45C_cjs.usePivotQuery; }
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "useSemanticQuery", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () { return chunkY3A3T45C_cjs.useSemanticQuery; }
|
|
150
|
+
});
|
|
151
|
+
exports.AuthGate = AuthGate;
|
|
152
|
+
exports.SemanticLayerProvider = SemanticLayerProvider;
|
|
153
|
+
//# sourceMappingURL=react.cjs.map
|
|
154
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/provider.tsx","../src/react/auth-gate.tsx"],"names":["useMemo","SemanticLayerClient","useState","useEffect","jsx","SemanticLayerContext","useAuth","Fragment","jsxs"],"mappings":";;;;;;;AAkBO,SAAS,qBAAA,CAAsB;AAAA,EACpC,UAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA,EAAQ,cAAA;AAAA,EACR;AACF,CAAA,EAA+B;AAC7B,EAAA,MAAM,MAAA,GAASA,cAAQ,MAAM;AAC3B,IAAA,IAAI,gBAAgB,OAAO,cAAA;AAC3B,IAAA,OAAO,IAAIC,qCAAA,CAAoB,EAAE,UAAA,EAAY,SAAS,CAAA;AAAA,EACxD,CAAA,EAAG,CAAC,UAAA,EAAY,OAAA,EAAS,cAAc,CAAC,CAAA;AAExC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIC,cAAA,CAAoB;AAAA,IAC1C,eAAA,EAAiB,KAAA;AAAA,IACjB,SAAA,EAAW,IAAA;AAAA,IACX,IAAA,EAAM,IAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACR,CAAA;AAED,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,OAAA,GAAU,IAAA;AAEd,IAAA,eAAe,QAAA,GAAW;AACxB,MAAA,IAAI;AACF,QAAA,MAAM,OAAA,GAAU,MAAM,MAAA,CAAO,U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AA;AAAA,MACC,KAAA,oBACCA,cAAAA,CAAC,GAAA,EAAA,EAAE,KAAA,EAAO,EAAE,MAAA,EAAQ,CAAA,EAAG,KAAA,EAAO,SAAA,EAAW,QAAA,EAAU,MAAA,IAAW,QAAA,EAAA,KAAA,EAAM,CAAA;AAAA,sBAEtEA,eAAC,QAAA,EAAA,EAAO,KAAA,EAAO,oBAAoB,OAAA,EAAS,MAAM,MAAA,EAAO,EAAG,QAAA,EAAA,qBAAA,EAE5D;AAAA,KAAA,EACF,CAAA;AAAA,EAEJ;AAEA,EAAA,uBAAOA,cAAAA,CAAAG,mBAAA,EAAA,EAAG,QAAA,EAAS,CAAA;AACrB","file":"react.cjs","sourcesContent":["import React, { useEffect, useMemo, useState } from \"react\";\nimport { SemanticLayerClient } from \"../client\";\nimport type { SemanticLayerConfig, AuthState } from \"../types\";\nimport { SemanticLayerContext } from \"./context\";\n\nexport interface SemanticLayerProviderProps {\n /** The Supabase URL of the gateway project. */\n gatewayUrl: string;\n /** The Supabase anon/publishable key of the gateway project. */\n anonKey: string;\n /**\n * Optional: a pre-constructed client instance.\n * If provided, gatewayUrl and anonKey are ignored.\n */\n client?: SemanticLayerClient;\n children: React.ReactNode;\n}\n\nexport function SemanticLayerProvider({\n gatewayUrl,\n anonKey,\n client: externalClient,\n children,\n}: SemanticLayerProviderProps) {\n const client = useMemo(() => {\n if (externalClient) return externalClient;\n return new SemanticLayerClient({ gatewayUrl, anonKey });\n }, [gatewayUrl, anonKey, externalClient]);\n\n const [auth, setAuth] = useState<AuthState>({\n isAuthenticated: false,\n isLoading: true,\n user: null,\n error: null,\n });\n\n useEffect(() => {\n let mounted = true;\n\n async function initAuth() {\n try {\n const session = await client.getSession();\n if (!mounted) return;\n\n if (session?.user) {\n setAuth({\n isAuthenticated: true,\n isLoading: false,\n user: { id: session.user.id, email: session.user.email || \"\" },\n error: null,\n });\n } else {\n setAuth({\n isAuthenticated: false,\n isLoading: false,\n user: null,\n error: null,\n });\n }\n } catch (err) {\n if (!mounted) return;\n setAuth({\n isAuthenticated: false,\n isLoading: false,\n user: null,\n error: err instanceof Error ? err.message : \"Auth initialization failed\",\n });\n }\n }\n\n initAuth();\n\n const { data: { subscription } } = client.onAuthStateChange((_event, session) => {\n if (!mounted) return;\n if (session?.user) {\n setAuth({\n isAuthenticated: true,\n isLoading: false,\n user: { id: session.user.id, email: session.user.email || \"\" },\n error: null,\n });\n } else {\n setAuth({\n isAuthenticated: false,\n isLoading: false,\n user: null,\n error: null,\n });\n }\n });\n\n return () => {\n mounted = false;\n subscription.unsubscribe();\n };\n }, [client]);\n\n const value = useMemo(() => ({ client, auth }), [client, auth]);\n\n return (\n <SemanticLayerContext.Provider value={value}>\n {children}\n </SemanticLayerContext.Provider>\n );\n}\n","import React from \"react\";\nimport { useAuth } from \"./hooks\";\n\nexport interface AuthGateProps {\n children: React.ReactNode;\n /** Custom loading component. */\n loading?: React.ReactNode;\n /** Custom sign-in component. Receives a signIn callback. */\n signInComponent?: (props: { signIn: () => void }) => React.ReactNode;\n}\n\nconst defaultLoadingStyle: React.CSSProperties = {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n minHeight: \"100vh\",\n fontFamily: \"system-ui, -apple-system, sans-serif\",\n color: \"#6b7280\",\n};\n\nconst defaultContainerStyle: React.CSSProperties = {\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n minHeight: \"100vh\",\n fontFamily: \"system-ui, -apple-system, sans-serif\",\n gap: \"16px\",\n};\n\nconst defaultButtonStyle: React.CSSProperties = {\n padding: \"12px 24px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#4285f4\",\n border: \"none\",\n borderRadius: \"8px\",\n cursor: \"pointer\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"8px\",\n};\n\n/**\n * Wraps children and only renders them when the user is authenticated.\n * Shows a sign-in screen when unauthenticated.\n */\nexport function AuthGate({ children, loading, signInComponent }: AuthGateProps) {\n const { isAuthenticated, isLoading, error, signIn, user } = useAuth();\n\n if (isLoading) {\n return <>{loading || <div style={defaultLoadingStyle}>Loading...</div>}</>;\n }\n\n if (!isAuthenticated) {\n if (signInComponent) {\n return <>{signInComponent({ signIn: () => signIn() })}</>;\n }\n\n return (\n <div style={defaultContainerStyle}>\n <h2 style={{ margin: 0, fontSize: \"24px\", color: \"#111827\" }}>Sign in to continue</h2>\n <p style={{ margin: 0, color: \"#6b7280\" }}>\n Use your inKind Google account to access data.\n </p>\n {error && (\n <p style={{ margin: 0, color: \"#ef4444\", fontSize: \"14px\" }}>{error}</p>\n )}\n <button style={defaultButtonStyle} onClick={() => signIn()}>\n Sign in with Google\n </button>\n </div>\n );\n }\n\n return <>{children}</>;\n}\n"]}
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import React__default from 'react';
|
|
4
|
+
import { SemanticLayerClient } from './index.cjs';
|
|
5
|
+
import * as _supabase_auth_js from '@supabase/auth-js';
|
|
6
|
+
import { S as SemanticField, a as FieldCategory, P as PivotConfig, Q as QueryResult, b as SimpleQueryInput, A as AuthState } from './types-Ds_6aDEw.cjs';
|
|
7
|
+
import '@supabase/supabase-js';
|
|
8
|
+
|
|
9
|
+
interface SemanticLayerProviderProps {
|
|
10
|
+
/** The Supabase URL of the gateway project. */
|
|
11
|
+
gatewayUrl: string;
|
|
12
|
+
/** The Supabase anon/publishable key of the gateway project. */
|
|
13
|
+
anonKey: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional: a pre-constructed client instance.
|
|
16
|
+
* If provided, gatewayUrl and anonKey are ignored.
|
|
17
|
+
*/
|
|
18
|
+
client?: SemanticLayerClient;
|
|
19
|
+
children: React__default.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
declare function SemanticLayerProvider({ gatewayUrl, anonKey, client: externalClient, children, }: SemanticLayerProviderProps): react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
23
|
+
interface AuthGateProps {
|
|
24
|
+
children: React__default.ReactNode;
|
|
25
|
+
/** Custom loading component. */
|
|
26
|
+
loading?: React__default.ReactNode;
|
|
27
|
+
/** Custom sign-in component. Receives a signIn callback. */
|
|
28
|
+
signInComponent?: (props: {
|
|
29
|
+
signIn: () => void;
|
|
30
|
+
}) => React__default.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Wraps children and only renders them when the user is authenticated.
|
|
34
|
+
* Shows a sign-in screen when unauthenticated.
|
|
35
|
+
*/
|
|
36
|
+
declare function AuthGate({ children, loading, signInComponent }: AuthGateProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
/** Returns the current auth state and sign-in/sign-out methods. */
|
|
39
|
+
declare function useAuth(): {
|
|
40
|
+
signIn: (redirectTo?: string) => Promise<_supabase_auth_js.OAuthResponse>;
|
|
41
|
+
signOut: () => Promise<{
|
|
42
|
+
error: _supabase_auth_js.AuthError | null;
|
|
43
|
+
}>;
|
|
44
|
+
isAuthenticated: boolean;
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
user: {
|
|
47
|
+
id: string;
|
|
48
|
+
email: string;
|
|
49
|
+
} | null;
|
|
50
|
+
error: string | null;
|
|
51
|
+
};
|
|
52
|
+
interface UseMetricsResult {
|
|
53
|
+
fields: SemanticField[];
|
|
54
|
+
metrics: SemanticField[];
|
|
55
|
+
dimensions: SemanticField[];
|
|
56
|
+
categories: FieldCategory[];
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
error: string | null;
|
|
59
|
+
refetch: () => void;
|
|
60
|
+
}
|
|
61
|
+
/** Fetch the full curated catalog of metrics and dimensions. */
|
|
62
|
+
declare function useMetrics(): UseMetricsResult;
|
|
63
|
+
interface UseSemanticQueryOptions {
|
|
64
|
+
/** Set to false to prevent the query from running automatically. */
|
|
65
|
+
enabled?: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface UseSemanticQueryResult {
|
|
68
|
+
data: QueryResult | null;
|
|
69
|
+
isLoading: boolean;
|
|
70
|
+
error: string | null;
|
|
71
|
+
refetch: () => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Execute a query against the dbt Semantic Layer using the simple input format.
|
|
75
|
+
* The query runs automatically when the input changes (unless enabled=false).
|
|
76
|
+
*/
|
|
77
|
+
declare function useSemanticQuery(input: SimpleQueryInput | null, options?: UseSemanticQueryOptions): UseSemanticQueryResult;
|
|
78
|
+
/**
|
|
79
|
+
* Execute a query using the full PivotConfig format.
|
|
80
|
+
* Use this for advanced use cases (column pivoting, custom aggregations).
|
|
81
|
+
*/
|
|
82
|
+
declare function usePivotQuery(config: PivotConfig | null, options?: UseSemanticQueryOptions): UseSemanticQueryResult;
|
|
83
|
+
|
|
84
|
+
interface SemanticLayerContextValue {
|
|
85
|
+
client: SemanticLayerClient;
|
|
86
|
+
auth: AuthState;
|
|
87
|
+
}
|
|
88
|
+
declare const SemanticLayerContext: React.Context<SemanticLayerContextValue | null>;
|
|
89
|
+
|
|
90
|
+
export { AuthGate, type AuthGateProps, SemanticLayerContext, type SemanticLayerContextValue, SemanticLayerProvider, type SemanticLayerProviderProps, useAuth, useMetrics, usePivotQuery, useSemanticQuery };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import React__default from 'react';
|
|
4
|
+
import { SemanticLayerClient } from './index.js';
|
|
5
|
+
import * as _supabase_auth_js from '@supabase/auth-js';
|
|
6
|
+
import { S as SemanticField, a as FieldCategory, P as PivotConfig, Q as QueryResult, b as SimpleQueryInput, A as AuthState } from './types-Ds_6aDEw.js';
|
|
7
|
+
import '@supabase/supabase-js';
|
|
8
|
+
|
|
9
|
+
interface SemanticLayerProviderProps {
|
|
10
|
+
/** The Supabase URL of the gateway project. */
|
|
11
|
+
gatewayUrl: string;
|
|
12
|
+
/** The Supabase anon/publishable key of the gateway project. */
|
|
13
|
+
anonKey: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional: a pre-constructed client instance.
|
|
16
|
+
* If provided, gatewayUrl and anonKey are ignored.
|
|
17
|
+
*/
|
|
18
|
+
client?: SemanticLayerClient;
|
|
19
|
+
children: React__default.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
declare function SemanticLayerProvider({ gatewayUrl, anonKey, client: externalClient, children, }: SemanticLayerProviderProps): react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
23
|
+
interface AuthGateProps {
|
|
24
|
+
children: React__default.ReactNode;
|
|
25
|
+
/** Custom loading component. */
|
|
26
|
+
loading?: React__default.ReactNode;
|
|
27
|
+
/** Custom sign-in component. Receives a signIn callback. */
|
|
28
|
+
signInComponent?: (props: {
|
|
29
|
+
signIn: () => void;
|
|
30
|
+
}) => React__default.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Wraps children and only renders them when the user is authenticated.
|
|
34
|
+
* Shows a sign-in screen when unauthenticated.
|
|
35
|
+
*/
|
|
36
|
+
declare function AuthGate({ children, loading, signInComponent }: AuthGateProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
/** Returns the current auth state and sign-in/sign-out methods. */
|
|
39
|
+
declare function useAuth(): {
|
|
40
|
+
signIn: (redirectTo?: string) => Promise<_supabase_auth_js.OAuthResponse>;
|
|
41
|
+
signOut: () => Promise<{
|
|
42
|
+
error: _supabase_auth_js.AuthError | null;
|
|
43
|
+
}>;
|
|
44
|
+
isAuthenticated: boolean;
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
user: {
|
|
47
|
+
id: string;
|
|
48
|
+
email: string;
|
|
49
|
+
} | null;
|
|
50
|
+
error: string | null;
|
|
51
|
+
};
|
|
52
|
+
interface UseMetricsResult {
|
|
53
|
+
fields: SemanticField[];
|
|
54
|
+
metrics: SemanticField[];
|
|
55
|
+
dimensions: SemanticField[];
|
|
56
|
+
categories: FieldCategory[];
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
error: string | null;
|
|
59
|
+
refetch: () => void;
|
|
60
|
+
}
|
|
61
|
+
/** Fetch the full curated catalog of metrics and dimensions. */
|
|
62
|
+
declare function useMetrics(): UseMetricsResult;
|
|
63
|
+
interface UseSemanticQueryOptions {
|
|
64
|
+
/** Set to false to prevent the query from running automatically. */
|
|
65
|
+
enabled?: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface UseSemanticQueryResult {
|
|
68
|
+
data: QueryResult | null;
|
|
69
|
+
isLoading: boolean;
|
|
70
|
+
error: string | null;
|
|
71
|
+
refetch: () => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Execute a query against the dbt Semantic Layer using the simple input format.
|
|
75
|
+
* The query runs automatically when the input changes (unless enabled=false).
|
|
76
|
+
*/
|
|
77
|
+
declare function useSemanticQuery(input: SimpleQueryInput | null, options?: UseSemanticQueryOptions): UseSemanticQueryResult;
|
|
78
|
+
/**
|
|
79
|
+
* Execute a query using the full PivotConfig format.
|
|
80
|
+
* Use this for advanced use cases (column pivoting, custom aggregations).
|
|
81
|
+
*/
|
|
82
|
+
declare function usePivotQuery(config: PivotConfig | null, options?: UseSemanticQueryOptions): UseSemanticQueryResult;
|
|
83
|
+
|
|
84
|
+
interface SemanticLayerContextValue {
|
|
85
|
+
client: SemanticLayerClient;
|
|
86
|
+
auth: AuthState;
|
|
87
|
+
}
|
|
88
|
+
declare const SemanticLayerContext: React.Context<SemanticLayerContextValue | null>;
|
|
89
|
+
|
|
90
|
+
export { AuthGate, type AuthGateProps, SemanticLayerContext, type SemanticLayerContextValue, SemanticLayerProvider, type SemanticLayerProviderProps, useAuth, useMetrics, usePivotQuery, useSemanticQuery };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { SemanticLayerClient } from './chunk-IQARBGJP.js';
|
|
2
|
+
import { SemanticLayerContext, useAuth } from './chunk-NJ4IJBV3.js';
|
|
3
|
+
export { SemanticLayerContext, useAuth, useMetrics, usePivotQuery, useSemanticQuery } from './chunk-NJ4IJBV3.js';
|
|
4
|
+
import { useMemo, useState, useEffect } from 'react';
|
|
5
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
function SemanticLayerProvider({
|
|
8
|
+
gatewayUrl,
|
|
9
|
+
anonKey,
|
|
10
|
+
client: externalClient,
|
|
11
|
+
children
|
|
12
|
+
}) {
|
|
13
|
+
const client = useMemo(() => {
|
|
14
|
+
if (externalClient) return externalClient;
|
|
15
|
+
return new SemanticLayerClient({ gatewayUrl, anonKey });
|
|
16
|
+
}, [gatewayUrl, anonKey, externalClient]);
|
|
17
|
+
const [auth, setAuth] = useState({
|
|
18
|
+
isAuthenticated: false,
|
|
19
|
+
isLoading: true,
|
|
20
|
+
user: null,
|
|
21
|
+
error: null
|
|
22
|
+
});
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
let mounted = true;
|
|
25
|
+
async function initAuth() {
|
|
26
|
+
try {
|
|
27
|
+
const session = await client.getSession();
|
|
28
|
+
if (!mounted) return;
|
|
29
|
+
if (session?.user) {
|
|
30
|
+
setAuth({
|
|
31
|
+
isAuthenticated: true,
|
|
32
|
+
isLoading: false,
|
|
33
|
+
user: { id: session.user.id, email: session.user.email || "" },
|
|
34
|
+
error: null
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
setAuth({
|
|
38
|
+
isAuthenticated: false,
|
|
39
|
+
isLoading: false,
|
|
40
|
+
user: null,
|
|
41
|
+
error: null
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (!mounted) return;
|
|
46
|
+
setAuth({
|
|
47
|
+
isAuthenticated: false,
|
|
48
|
+
isLoading: false,
|
|
49
|
+
user: null,
|
|
50
|
+
error: err instanceof Error ? err.message : "Auth initialization failed"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
initAuth();
|
|
55
|
+
const { data: { subscription } } = client.onAuthStateChange((_event, session) => {
|
|
56
|
+
if (!mounted) return;
|
|
57
|
+
if (session?.user) {
|
|
58
|
+
setAuth({
|
|
59
|
+
isAuthenticated: true,
|
|
60
|
+
isLoading: false,
|
|
61
|
+
user: { id: session.user.id, email: session.user.email || "" },
|
|
62
|
+
error: null
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
setAuth({
|
|
66
|
+
isAuthenticated: false,
|
|
67
|
+
isLoading: false,
|
|
68
|
+
user: null,
|
|
69
|
+
error: null
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return () => {
|
|
74
|
+
mounted = false;
|
|
75
|
+
subscription.unsubscribe();
|
|
76
|
+
};
|
|
77
|
+
}, [client]);
|
|
78
|
+
const value = useMemo(() => ({ client, auth }), [client, auth]);
|
|
79
|
+
return /* @__PURE__ */ jsx(SemanticLayerContext.Provider, { value, children });
|
|
80
|
+
}
|
|
81
|
+
var defaultLoadingStyle = {
|
|
82
|
+
display: "flex",
|
|
83
|
+
alignItems: "center",
|
|
84
|
+
justifyContent: "center",
|
|
85
|
+
minHeight: "100vh",
|
|
86
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
87
|
+
color: "#6b7280"
|
|
88
|
+
};
|
|
89
|
+
var defaultContainerStyle = {
|
|
90
|
+
display: "flex",
|
|
91
|
+
flexDirection: "column",
|
|
92
|
+
alignItems: "center",
|
|
93
|
+
justifyContent: "center",
|
|
94
|
+
minHeight: "100vh",
|
|
95
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
96
|
+
gap: "16px"
|
|
97
|
+
};
|
|
98
|
+
var defaultButtonStyle = {
|
|
99
|
+
padding: "12px 24px",
|
|
100
|
+
fontSize: "16px",
|
|
101
|
+
fontWeight: 500,
|
|
102
|
+
color: "#ffffff",
|
|
103
|
+
backgroundColor: "#4285f4",
|
|
104
|
+
border: "none",
|
|
105
|
+
borderRadius: "8px",
|
|
106
|
+
cursor: "pointer",
|
|
107
|
+
display: "flex",
|
|
108
|
+
alignItems: "center",
|
|
109
|
+
gap: "8px"
|
|
110
|
+
};
|
|
111
|
+
function AuthGate({ children, loading, signInComponent }) {
|
|
112
|
+
const { isAuthenticated, isLoading, error, signIn, user } = useAuth();
|
|
113
|
+
if (isLoading) {
|
|
114
|
+
return /* @__PURE__ */ jsx(Fragment, { children: loading || /* @__PURE__ */ jsx("div", { style: defaultLoadingStyle, children: "Loading..." }) });
|
|
115
|
+
}
|
|
116
|
+
if (!isAuthenticated) {
|
|
117
|
+
if (signInComponent) {
|
|
118
|
+
return /* @__PURE__ */ jsx(Fragment, { children: signInComponent({ signIn: () => signIn() }) });
|
|
119
|
+
}
|
|
120
|
+
return /* @__PURE__ */ jsxs("div", { style: defaultContainerStyle, children: [
|
|
121
|
+
/* @__PURE__ */ jsx("h2", { style: { margin: 0, fontSize: "24px", color: "#111827" }, children: "Sign in to continue" }),
|
|
122
|
+
/* @__PURE__ */ jsx("p", { style: { margin: 0, color: "#6b7280" }, children: "Use your inKind Google account to access data." }),
|
|
123
|
+
error && /* @__PURE__ */ jsx("p", { style: { margin: 0, color: "#ef4444", fontSize: "14px" }, children: error }),
|
|
124
|
+
/* @__PURE__ */ jsx("button", { style: defaultButtonStyle, onClick: () => signIn(), children: "Sign in with Google" })
|
|
125
|
+
] });
|
|
126
|
+
}
|
|
127
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { AuthGate, SemanticLayerProvider };
|
|
131
|
+
//# sourceMappingURL=react.js.map
|
|
132
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/provider.tsx","../src/react/auth-gate.tsx"],"names":["jsx"],"mappings":";;;;;;AAkBO,SAAS,qBAAA,CAAsB;AAAA,E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AA,YAAA,EAAU,CAAA,EAAO,CAAA;AAAA,EACzE;AAEA,EAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,IAAA,IAAI,eAAA,EAAiB;AACnB,MAAA,uBAAOA,GAAAA,CAAA,QAAA,EAAA,EAAG,QAAA,EAAA,eAAA,CAAgB,EAAE,QAAQ,MAAM,MAAA,EAAO,EAAG,CAAA,EAAE,CAAA;AAAA,IACxD;AAEA,IAAA,uBACE,IAAA,CAAC,KAAA,EAAA,EAAI,KAAA,EAAO,qBAAA,EACV,QAAA,EAAA;AAAA,sBAAAA,GAAAA,CAAC,IAAA,EAAA,EAAG,KAAA,EAAO,EAAE,MAAA,EAAQ,CAAA,EAAG,QAAA,EAAU,MAAA,EAAQ,KAAA,EAAO,SAAA,EAAU,EAAG,QAAA,EAAA,qBAAA,EAAmB,CAAA;AAAA,sBACjFA,GAAAA,CAAC,GAAA,EAAA,EAAE,KAAA,EAAO,EAAE,QAAQ,CAAA,EAAG,KAAA,EAAO,SAAA,EAAU,EAAG,QAAA,EAAA,gDAAA,EAE3C,CAAA;AAAA,MACC,KAAA,oBACCA,GAAAA,CAAC,GAAA,EAAA,EAAE,KAAA,EAAO,EAAE,MAAA,EAAQ,CAAA,EAAG,KAAA,EAAO,SAAA,EAAW,QAAA,EAAU,MAAA,IAAW,QAAA,EAAA,KAAA,EAAM,CAAA;AAAA,sBAEtEA,IAAC,QAAA,EAAA,EAAO,KAAA,EAAO,oBAAoB,OAAA,EAAS,MAAM,MAAA,EAAO,EAAG,QAAA,EAAA,qBAAA,EAE5D;AAAA,KAAA,EACF,CAAA;AAAA,EAEJ;AAEA,EAAA,uBAAOA,GAAAA,CAAA,QAAA,EAAA,EAAG,QAAA,EAAS,CAAA;AACrB","file":"react.js","sourcesContent":["import React, { useEffect, useMemo, useState } from \"react\";\nimport { SemanticLayerClient } from \"../client\";\nimport type { SemanticLayerConfig, AuthState } from \"../types\";\nimport { SemanticLayerContext } from \"./context\";\n\nexport interface SemanticLayerProviderProps {\n /** The Supabase URL of the gateway project. */\n gatewayUrl: string;\n /** The Supabase anon/publishable key of the gateway project. */\n anonKey: string;\n /**\n * Optional: a pre-constructed client instance.\n * If provided, gatewayUrl and anonKey are ignored.\n */\n client?: SemanticLayerClient;\n children: React.ReactNode;\n}\n\nexport function SemanticLayerProvider({\n gatewayUrl,\n anonKey,\n client: externalClient,\n children,\n}: SemanticLayerProviderProps) {\n const client = useMemo(() => {\n if (externalClient) return externalClient;\n return new SemanticLayerClient({ gatewayUrl, anonKey });\n }, [gatewayUrl, anonKey, externalClient]);\n\n const [auth, setAuth] = useState<AuthState>({\n isAuthenticated: false,\n isLoading: true,\n user: null,\n error: null,\n });\n\n useEffect(() => {\n let mounted = true;\n\n async function initAuth() {\n try {\n const session = await client.getSession();\n if (!mounted) return;\n\n if (session?.user) {\n setAuth({\n isAuthenticated: true,\n isLoading: false,\n user: { id: session.user.id, email: session.user.email || \"\" },\n error: null,\n });\n } else {\n setAuth({\n isAuthenticated: false,\n isLoading: false,\n user: null,\n error: null,\n });\n }\n } catch (err) {\n if (!mounted) return;\n setAuth({\n isAuthenticated: false,\n isLoading: false,\n user: null,\n error: err instanceof Error ? err.message : \"Auth initialization failed\",\n });\n }\n }\n\n initAuth();\n\n const { data: { subscription } } = client.onAuthStateChange((_event, session) => {\n if (!mounted) return;\n if (session?.user) {\n setAuth({\n isAuthenticated: true,\n isLoading: false,\n user: { id: session.user.id, email: session.user.email || \"\" },\n error: null,\n });\n } else {\n setAuth({\n isAuthenticated: false,\n isLoading: false,\n user: null,\n error: null,\n });\n }\n });\n\n return () => {\n mounted = false;\n subscription.unsubscribe();\n };\n }, [client]);\n\n const value = useMemo(() => ({ client, auth }), [client, auth]);\n\n return (\n <SemanticLayerContext.Provider value={value}>\n {children}\n </SemanticLayerContext.Provider>\n );\n}\n","import React from \"react\";\nimport { useAuth } from \"./hooks\";\n\nexport interface AuthGateProps {\n children: React.ReactNode;\n /** Custom loading component. */\n loading?: React.ReactNode;\n /** Custom sign-in component. Receives a signIn callback. */\n signInComponent?: (props: { signIn: () => void }) => React.ReactNode;\n}\n\nconst defaultLoadingStyle: React.CSSProperties = {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n minHeight: \"100vh\",\n fontFamily: \"system-ui, -apple-system, sans-serif\",\n color: \"#6b7280\",\n};\n\nconst defaultContainerStyle: React.CSSProperties = {\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n minHeight: \"100vh\",\n fontFamily: \"system-ui, -apple-system, sans-serif\",\n gap: \"16px\",\n};\n\nconst defaultButtonStyle: React.CSSProperties = {\n padding: \"12px 24px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#4285f4\",\n border: \"none\",\n borderRadius: \"8px\",\n cursor: \"pointer\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"8px\",\n};\n\n/**\n * Wraps children and only renders them when the user is authenticated.\n * Shows a sign-in screen when unauthenticated.\n */\nexport function AuthGate({ children, loading, signInComponent }: AuthGateProps) {\n const { isAuthenticated, isLoading, error, signIn, user } = useAuth();\n\n if (isLoading) {\n return <>{loading || <div style={defaultLoadingStyle}>Loading...</div>}</>;\n }\n\n if (!isAuthenticated) {\n if (signInComponent) {\n return <>{signInComponent({ signIn: () => signIn() })}</>;\n }\n\n return (\n <div style={defaultContainerStyle}>\n <h2 style={{ margin: 0, fontSize: \"24px\", color: \"#111827\" }}>Sign in to continue</h2>\n <p style={{ margin: 0, color: \"#6b7280\" }}>\n Use your inKind Google account to access data.\n </p>\n {error && (\n <p style={{ margin: 0, color: \"#ef4444\", fontSize: \"14px\" }}>{error}</p>\n )}\n <button style={defaultButtonStyle} onClick={() => signIn()}>\n Sign in with Google\n </button>\n </div>\n );\n }\n\n return <>{children}</>;\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
type FieldType = "metric" | "dimension" | "time_dimension" | "entity";
|
|
2
|
+
type AggregationType = "sum" | "avg" | "count" | "min" | "max" | "count_distinct";
|
|
3
|
+
type TimeGrain = "day" | "week" | "month" | "quarter" | "year";
|
|
4
|
+
type DataType = "number" | "string" | "date" | "boolean";
|
|
5
|
+
interface SemanticField {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
description: string;
|
|
10
|
+
type: FieldType;
|
|
11
|
+
dataType: DataType;
|
|
12
|
+
category: string;
|
|
13
|
+
aggregation?: AggregationType;
|
|
14
|
+
defaultGrain?: TimeGrain;
|
|
15
|
+
compatibleWith?: string[];
|
|
16
|
+
tags?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface FieldCategory {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
interface MetadataResponse {
|
|
23
|
+
fields: SemanticField[];
|
|
24
|
+
categories: FieldCategory[];
|
|
25
|
+
}
|
|
26
|
+
interface PivotField {
|
|
27
|
+
fieldId: string;
|
|
28
|
+
field: SemanticField;
|
|
29
|
+
aggregation?: AggregationType;
|
|
30
|
+
grain?: TimeGrain;
|
|
31
|
+
filterValues?: string[];
|
|
32
|
+
filterOperator?: "in" | "not_in" | "gt" | "lt" | "gte" | "lte" | "between";
|
|
33
|
+
filterRange?: [string, string];
|
|
34
|
+
sortDirection?: "asc" | "desc";
|
|
35
|
+
}
|
|
36
|
+
interface PivotConfig {
|
|
37
|
+
values: PivotField[];
|
|
38
|
+
rows: PivotField[];
|
|
39
|
+
columns: PivotField[];
|
|
40
|
+
filters: PivotField[];
|
|
41
|
+
}
|
|
42
|
+
interface QueryColumn {
|
|
43
|
+
key: string;
|
|
44
|
+
label: string;
|
|
45
|
+
dataType: DataType;
|
|
46
|
+
}
|
|
47
|
+
interface QueryResult {
|
|
48
|
+
columns: QueryColumn[];
|
|
49
|
+
rows: Record<string, unknown>[];
|
|
50
|
+
totalRows: number;
|
|
51
|
+
executionTimeMs: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Simplified query input for the SDK (alternative to the full PivotConfig).
|
|
55
|
+
* Lets callers specify metrics/dimensions by name without building full PivotField objects.
|
|
56
|
+
*/
|
|
57
|
+
interface SimpleQueryInput {
|
|
58
|
+
metrics: string[];
|
|
59
|
+
groupBy?: string[];
|
|
60
|
+
grain?: TimeGrain;
|
|
61
|
+
filters?: Record<string, string[]>;
|
|
62
|
+
orderBy?: string;
|
|
63
|
+
limit?: number;
|
|
64
|
+
}
|
|
65
|
+
interface SemanticLayerConfig {
|
|
66
|
+
gatewayUrl: string;
|
|
67
|
+
anonKey: string;
|
|
68
|
+
}
|
|
69
|
+
interface AuthState {
|
|
70
|
+
isAuthenticated: boolean;
|
|
71
|
+
isLoading: boolean;
|
|
72
|
+
user: {
|
|
73
|
+
id: string;
|
|
74
|
+
email: string;
|
|
75
|
+
} | null;
|
|
76
|
+
error: string | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type { AuthState as A, DataType as D, FieldType as F, MetadataResponse as M, PivotConfig as P, QueryResult as Q, SemanticField as S, TimeGrain as T, FieldCategory as a, SimpleQueryInput as b, SemanticLayerConfig as c, AggregationType as d, PivotField as e, QueryColumn as f };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
type FieldType = "metric" | "dimension" | "time_dimension" | "entity";
|
|
2
|
+
type AggregationType = "sum" | "avg" | "count" | "min" | "max" | "count_distinct";
|
|
3
|
+
type TimeGrain = "day" | "week" | "month" | "quarter" | "year";
|
|
4
|
+
type DataType = "number" | "string" | "date" | "boolean";
|
|
5
|
+
interface SemanticField {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
description: string;
|
|
10
|
+
type: FieldType;
|
|
11
|
+
dataType: DataType;
|
|
12
|
+
category: string;
|
|
13
|
+
aggregation?: AggregationType;
|
|
14
|
+
defaultGrain?: TimeGrain;
|
|
15
|
+
compatibleWith?: string[];
|
|
16
|
+
tags?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface FieldCategory {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
interface MetadataResponse {
|
|
23
|
+
fields: SemanticField[];
|
|
24
|
+
categories: FieldCategory[];
|
|
25
|
+
}
|
|
26
|
+
interface PivotField {
|
|
27
|
+
fieldId: string;
|
|
28
|
+
field: SemanticField;
|
|
29
|
+
aggregation?: AggregationType;
|
|
30
|
+
grain?: TimeGrain;
|
|
31
|
+
filterValues?: string[];
|
|
32
|
+
filterOperator?: "in" | "not_in" | "gt" | "lt" | "gte" | "lte" | "between";
|
|
33
|
+
filterRange?: [string, string];
|
|
34
|
+
sortDirection?: "asc" | "desc";
|
|
35
|
+
}
|
|
36
|
+
interface PivotConfig {
|
|
37
|
+
values: PivotField[];
|
|
38
|
+
rows: PivotField[];
|
|
39
|
+
columns: PivotField[];
|
|
40
|
+
filters: PivotField[];
|
|
41
|
+
}
|
|
42
|
+
interface QueryColumn {
|
|
43
|
+
key: string;
|
|
44
|
+
label: string;
|
|
45
|
+
dataType: DataType;
|
|
46
|
+
}
|
|
47
|
+
interface QueryResult {
|
|
48
|
+
columns: QueryColumn[];
|
|
49
|
+
rows: Record<string, unknown>[];
|
|
50
|
+
totalRows: number;
|
|
51
|
+
executionTimeMs: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Simplified query input for the SDK (alternative to the full PivotConfig).
|
|
55
|
+
* Lets callers specify metrics/dimensions by name without building full PivotField objects.
|
|
56
|
+
*/
|
|
57
|
+
interface SimpleQueryInput {
|
|
58
|
+
metrics: string[];
|
|
59
|
+
groupBy?: string[];
|
|
60
|
+
grain?: TimeGrain;
|
|
61
|
+
filters?: Record<string, string[]>;
|
|
62
|
+
orderBy?: string;
|
|
63
|
+
limit?: number;
|
|
64
|
+
}
|
|
65
|
+
interface SemanticLayerConfig {
|
|
66
|
+
gatewayUrl: string;
|
|
67
|
+
anonKey: string;
|
|
68
|
+
}
|
|
69
|
+
interface AuthState {
|
|
70
|
+
isAuthenticated: boolean;
|
|
71
|
+
isLoading: boolean;
|
|
72
|
+
user: {
|
|
73
|
+
id: string;
|
|
74
|
+
email: string;
|
|
75
|
+
} | null;
|
|
76
|
+
error: string | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type { AuthState as A, DataType as D, FieldType as F, MetadataResponse as M, PivotConfig as P, QueryResult as Q, SemanticField as S, TimeGrain as T, FieldCategory as a, SimpleQueryInput as b, SemanticLayerConfig as c, AggregationType as d, PivotField as e, QueryColumn as f };
|