@magemetrics/core 0.5.4 → 0.6.1

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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Client } from 'openapi-fetch';
2
2
  import { DefaultChatTransport } from 'ai';
3
+ import { GoTrueClient } from '@supabase/auth-js';
3
4
  import { GoTrueClientOptions } from '@supabase/auth-js';
4
5
  import { HttpChatTransportInitOptions } from 'ai';
5
6
  import type { InferUITool } from 'ai';
@@ -63,6 +64,54 @@ declare interface AsyncStorage_2 {
63
64
  removeItem(key: string): Promise<void>;
64
65
  }
65
66
 
67
+ /**
68
+ * Authentication provider interface for MageMetrics client.
69
+ * Providers handle token management and header generation.
70
+ */
71
+ export declare interface AuthProvider {
72
+ /**
73
+ * Initialize the auth provider and perform any necessary setup.
74
+ */
75
+ initialize(): Promise<void>;
76
+ /**
77
+ * Get authentication headers to include in API requests.
78
+ */
79
+ getHeaders(): Promise<Record<string, string>>;
80
+ /**
81
+ * Get the current authentication state.
82
+ */
83
+ getState(): AuthState;
84
+ /**
85
+ * Update the external JWT (if applicable).
86
+ */
87
+ updateExternalJwt(jwt: string): Promise<void>;
88
+ /**
89
+ * Logout and clear any stored tokens.
90
+ */
91
+ logout(): Promise<void>;
92
+ /**
93
+ * Get the Supabase client (if available).
94
+ * Used for backward compatibility with existing code.
95
+ */
96
+ getSupabaseClient(): GoTrueClient | null;
97
+ /**
98
+ * Add an event listener for auth events.
99
+ * @param type the type of the event
100
+ * @param listener the listener to add
101
+ * @param options options for the event listener
102
+ * @param options.signal an AbortSignal to remove the listener when aborted
103
+ */
104
+ addEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>, options?: {
105
+ signal?: AbortSignal;
106
+ }): void;
107
+ /**
108
+ * Remove an event listener.
109
+ * @param type the type of the event
110
+ * @param listener the listener to remove
111
+ */
112
+ removeEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>): void;
113
+ }
114
+
66
115
  /**
67
116
  * Authentication states
68
117
  */
@@ -275,6 +324,97 @@ declare type CustomDataParts = {
275
324
  };
276
325
  };
277
326
 
327
+ /**
328
+ * Direct authentication provider that uses a Supabase JWT directly
329
+ * without going through the token exchange flow.
330
+ *
331
+ * This provider:
332
+ * - Does NOT create shadow users
333
+ * - Does NOT call the exchange endpoint
334
+ * - Simply returns the JWT in headers for backend validation
335
+ * - Preserves the original user's roles and permissions
336
+ *
337
+ * Use this for internal admin tools where you already have a valid
338
+ * Supabase JWT and want to bypass the external auth flow.
339
+ * @example
340
+ * ```typescript
341
+ * const authProvider = new DirectAuthProvider(internalUserJwt);
342
+ * const client = new MageMetricsClient(config, authProvider);
343
+ * ```
344
+ */
345
+ export declare class DirectAuthProvider implements AuthProvider {
346
+ private state;
347
+ private jwt;
348
+ private events;
349
+ constructor(jwt: string);
350
+ initialize(): Promise<void>;
351
+ getHeaders(): Promise<Record<string, string>>;
352
+ getState(): AuthState;
353
+ updateExternalJwt(jwt: string): Promise<void>;
354
+ logout(): Promise<void>;
355
+ getSupabaseClient(): GoTrueClient | null;
356
+ addEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>, options?: {
357
+ signal?: AbortSignal;
358
+ }): void;
359
+ removeEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>): void;
360
+ private setState;
361
+ }
362
+
363
+ /**
364
+ * External authentication provider that handles the full token exchange flow.
365
+ *
366
+ * This provider:
367
+ * - Calls the exchange endpoint to create shadow users
368
+ * - Manages Supabase sessions
369
+ * - Handles token refresh
370
+ * - Supports auto-refresh and session management
371
+ *
372
+ * This is the default provider used for external customer integrations.
373
+ */
374
+ export declare class ExternalAuthProvider implements AuthProvider {
375
+ private config;
376
+ private state;
377
+ private supabaseClient;
378
+ private noAuthApiClient;
379
+ private authApiResponse;
380
+ private processedJwt;
381
+ private userId;
382
+ private events;
383
+ constructor(config: ExternalAuthProviderConfig);
384
+ initialize(): Promise<void>;
385
+ getHeaders(): Promise<Record<string, string>>;
386
+ getState(): AuthState;
387
+ updateExternalJwt(jwt: string): Promise<void>;
388
+ logout(): Promise<void>;
389
+ getSupabaseClient(): GoTrueClient | null;
390
+ addEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>, options?: {
391
+ signal?: AbortSignal;
392
+ }): void;
393
+ removeEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>): void;
394
+ startAutoRefresh(): Promise<void> | undefined;
395
+ stopAutoRefresh(): Promise<void> | undefined;
396
+ private getApiInformation;
397
+ private initializeSupabaseClient;
398
+ private handleAuthentication;
399
+ private exchangeExternalToken;
400
+ private setState;
401
+ private encodeCheckKey;
402
+ private saveCheckKey;
403
+ private compareCheckKey;
404
+ private clearCheckKey;
405
+ private clearStorage;
406
+ }
407
+
408
+ export declare interface ExternalAuthProviderConfig {
409
+ apiUrl: string;
410
+ apiKey: string;
411
+ externalJwt?: string;
412
+ additionalHeaders?: Record<string, string>;
413
+ storage: AsyncStorage_2;
414
+ applicationName?: string;
415
+ authOptions?: Pick<GoTrueClientOptions, "fetch">;
416
+ }
417
+
278
418
  declare type ExtractInsightResponse = z.infer<typeof ExtractInsightResponseSchema>;
279
419
 
280
420
  declare const ExtractInsightResponseSchema: z.ZodUnion<[z.ZodObject<{
@@ -305,7 +445,10 @@ export declare type GenerateInsightParam = {
305
445
 
306
446
  export declare const getPublicApiClient: (apiUrl: string, apiKey: string) => Client<NoAuthPaths>;
307
447
 
448
+ declare const HEADER_SP_TOKEN: "sp-access-token";
449
+
308
450
  declare const inputSchema: z.ZodObject<{
451
+ rawRequest: z.ZodString;
309
452
  userRequest: z.ZodString;
310
453
  isNewAnalysisGoal: z.ZodBoolean;
311
454
  responseType: z.ZodEnum<{
@@ -365,18 +508,10 @@ declare type MageMetricsChatTransportOptions = Omit<HttpChatTransportInitOptions
365
508
  */
366
509
  export declare class MageMetricsClient {
367
510
  private config;
368
- private authState;
369
- private supabaseClient;
511
+ private authProvider;
370
512
  private internalApiClient;
371
- private noAuthApiClient;
372
- private authApiResponse;
373
513
  private authPromise;
374
- private processedJwt;
375
- private userId;
376
- private storageAdapter;
377
- private events;
378
- private authOptions;
379
- constructor(config: MageMetricsClientConfig, auth?: Pick<GoTrueClientOptions, "fetch">);
514
+ constructor(config: MageMetricsClientConfig, authProviderOrAuthOptions?: AuthProvider | Pick<GoTrueClientOptions, "fetch">);
380
515
  toJSON(): {
381
516
  config: string;
382
517
  };
@@ -404,7 +539,6 @@ export declare class MageMetricsClient {
404
539
  updateExternalJwt(jwt: string): Promise<void>;
405
540
  get state(): AuthState;
406
541
  getHeaders(): Promise<Record<string, string>>;
407
- private clearStorage;
408
542
  logout(): Promise<void>;
409
543
  auth: {
410
544
  startAutoRefresh: () => Promise<void> | undefined;
@@ -480,6 +614,16 @@ export declare class MageMetricsClient {
480
614
  null_count: number | null;
481
615
  unique_count: number | null;
482
616
  unique_percentage: number | null;
617
+ min_value?: number | null;
618
+ max_value?: number | null;
619
+ avg_value?: number | null;
620
+ median_value?: number | null;
621
+ std_value?: number | null;
622
+ min_date?: string | null;
623
+ max_date?: string | null;
624
+ min_length?: number | null;
625
+ max_length?: number | null;
626
+ avg_length?: number | null;
483
627
  } & {
484
628
  [key: string]: unknown;
485
629
  };
@@ -577,27 +721,8 @@ export declare class MageMetricsClient {
577
721
  }[]>;
578
722
  }>;
579
723
  };
580
- /**
581
- * Perform the complete authentication flow
582
- */
583
- private performAuthFlow;
584
- private getApiInformation;
585
- private initializeSupabaseClient;
586
724
  client(): InternalApiClient;
587
- /**
588
- * Handle the authentication logic (check session or exchange token)
589
- */
590
- private handleAuthentication;
591
- /**
592
- * Exchange external JWT for Supabase tokens
593
- */
594
- private exchangeExternalToken;
595
725
  private createSupabaseHeaderMiddleware;
596
- private setState;
597
- private encodeCheckKey;
598
- saveCheckKey(externalJwt: string, apiKey: string): Promise<void>;
599
- compareCheckKey(externalJwt: string, apiKey: string): Promise<boolean>;
600
- clearCheckKey(): Promise<void>;
601
726
  }
602
727
 
603
728
  /**
@@ -1149,6 +1274,16 @@ declare interface operations {
1149
1274
  null_count: number | null;
1150
1275
  unique_count: number | null;
1151
1276
  unique_percentage: number | null;
1277
+ min_value?: number | null;
1278
+ max_value?: number | null;
1279
+ avg_value?: number | null;
1280
+ median_value?: number | null;
1281
+ std_value?: number | null;
1282
+ min_date?: string | null;
1283
+ max_date?: string | null;
1284
+ min_length?: number | null;
1285
+ max_length?: number | null;
1286
+ avg_length?: number | null;
1152
1287
  } & {
1153
1288
  [key: string]: unknown;
1154
1289
  };
@@ -1435,6 +1570,8 @@ declare interface operations {
1435
1570
  friendliness_score?: number;
1436
1571
  friendliness_score_reason?: string;
1437
1572
  flow_data_id: number;
1573
+ output_dataset?: string;
1574
+ sql?: string;
1438
1575
  };
1439
1576
  };
1440
1577
  };
@@ -1799,6 +1936,16 @@ declare interface operations {
1799
1936
  null_count: number | null;
1800
1937
  unique_count: number | null;
1801
1938
  unique_percentage: number | null;
1939
+ min_value?: number | null;
1940
+ max_value?: number | null;
1941
+ avg_value?: number | null;
1942
+ median_value?: number | null;
1943
+ std_value?: number | null;
1944
+ min_date?: string | null;
1945
+ max_date?: string | null;
1946
+ min_length?: number | null;
1947
+ max_length?: number | null;
1948
+ avg_length?: number | null;
1802
1949
  } & {
1803
1950
  [key: string]: unknown;
1804
1951
  };
@@ -4447,9 +4594,9 @@ declare type TableFilters = Record<string, string | number>;
4447
4594
  */
4448
4595
  export declare const TOKEN_STORAGE_KEY = "mm-ai-sp-token";
4449
4596
 
4450
- declare type ToRemove = Simplify<{
4451
- header: "sp-access-token";
4452
- }>;
4597
+ declare type ToRemove = {
4598
+ header: typeof HEADER_SP_TOKEN;
4599
+ };
4453
4600
 
4454
4601
  declare type UiTool = InferUITool<Tool<z.infer<typeof inputSchema>, z.infer<typeof redactedOutputSchema>>>;
4455
4602