@magemetrics/core 0.0.59
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/package.json +59 -0
- package/dist/src/adapters/storage/browser.d.ts +11 -0
- package/dist/src/adapters/storage/browser.d.ts.map +1 -0
- package/dist/src/adapters/storage/browser.js +37 -0
- package/dist/src/adapters/storage/browser.js.map +1 -0
- package/dist/src/adapters/storage/factory.d.ts +8 -0
- package/dist/src/adapters/storage/factory.d.ts.map +1 -0
- package/dist/src/adapters/storage/factory.js +24 -0
- package/dist/src/adapters/storage/factory.js.map +1 -0
- package/dist/src/adapters/storage/interface.d.ts +26 -0
- package/dist/src/adapters/storage/interface.d.ts.map +1 -0
- package/dist/src/adapters/storage/interface.js +1 -0
- package/dist/src/adapters/storage/interface.js.map +1 -0
- package/dist/src/adapters/storage/memory.d.ts +11 -0
- package/dist/src/adapters/storage/memory.d.ts.map +1 -0
- package/dist/src/adapters/storage/memory.js +20 -0
- package/dist/src/adapters/storage/memory.js.map +1 -0
- package/dist/src/core/MageMetricsClient.d.ts +103 -0
- package/dist/src/core/MageMetricsClient.d.ts.map +1 -0
- package/dist/src/core/MageMetricsClient.js +509 -0
- package/dist/src/core/MageMetricsClient.js.map +1 -0
- package/dist/src/core/MageMetricsEventEmitter.d.ts +25 -0
- package/dist/src/core/MageMetricsEventEmitter.d.ts.map +1 -0
- package/dist/src/core/MageMetricsEventEmitter.js +48 -0
- package/dist/src/core/MageMetricsEventEmitter.js.map +1 -0
- package/dist/src/core/types.d.ts +37 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +6 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils/hash.d.ts +8 -0
- package/dist/src/utils/hash.d.ts.map +1 -0
- package/dist/src/utils/hash.js +16 -0
- package/dist/src/utils/hash.js.map +1 -0
- package/dist/src/utils/platform.d.ts +10 -0
- package/dist/src/utils/platform.d.ts.map +1 -0
- package/dist/src/utils/platform.js +25 -0
- package/dist/src/utils/platform.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { addApiKeyHeader, addVersionHeader, ApiError, throwOnError, } from "@mm/shared/api/client/middleware";
|
|
2
|
+
import { GenerateInsight, } from "@mm/shared/endpoints/admin-console/contextualInsights.routes";
|
|
3
|
+
import { ExchangeExternalToken, GetApiInformation, } from "@mm/shared/endpoints/auth.routes";
|
|
4
|
+
import { RetrieveDashboard } from "@mm/shared/endpoints/companion/dashboards.routes";
|
|
5
|
+
import { CreateFlow, ExportReportData, RetrieveRecentFlows, } from "@mm/shared/endpoints/companion/flows.routes";
|
|
6
|
+
import { TriggerFlow } from "@mm/shared/endpoints/companion/triggers.routes";
|
|
7
|
+
import { RunEnd2EndFlowRoute } from "@mm/shared/endpoints/end2end/run.routes";
|
|
8
|
+
import { GoTrueClient } from "@supabase/auth-js";
|
|
9
|
+
import createApiClient, {} from "openapi-fetch";
|
|
10
|
+
import { createStorageAdapter } from "#adapters/storage/factory";
|
|
11
|
+
import { hashString } from "#utils/hash";
|
|
12
|
+
import packageJson from "../../package.json";
|
|
13
|
+
import { MageMetricsEventEmitter, } from "./MageMetricsEventEmitter";
|
|
14
|
+
import { CHECK_KEY, TOKEN_STORAGE_KEY, } from "./types";
|
|
15
|
+
const MM_CLIENT_VERSION = packageJson.version;
|
|
16
|
+
export const getPublicApiClient = (apiUrl, apiKey) => {
|
|
17
|
+
const client = createApiClient({ baseUrl: apiUrl });
|
|
18
|
+
client.use(throwOnError);
|
|
19
|
+
client.use(addVersionHeader(MM_CLIENT_VERSION));
|
|
20
|
+
client.use(addApiKeyHeader(apiKey));
|
|
21
|
+
return client;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Core MageMetrics client that handles authentication lifecycle and provides
|
|
25
|
+
* a promise-based API that automatically waits for authentication to complete.
|
|
26
|
+
*
|
|
27
|
+
* This version uses composition instead of inheritance and pluggable storage adapters
|
|
28
|
+
* for cross-platform compatibility.
|
|
29
|
+
*/
|
|
30
|
+
export class MageMetricsClient {
|
|
31
|
+
config;
|
|
32
|
+
authState = "initializing";
|
|
33
|
+
supabaseClient = null;
|
|
34
|
+
internalApiClient = null;
|
|
35
|
+
noAuthApiClient = null;
|
|
36
|
+
authApiResponse = null;
|
|
37
|
+
authPromise = null;
|
|
38
|
+
processedJwt = Symbol("initial");
|
|
39
|
+
storageAdapter;
|
|
40
|
+
events = new MageMetricsEventEmitter();
|
|
41
|
+
constructor(config) {
|
|
42
|
+
this.config = config;
|
|
43
|
+
// Initialize storage adapter - either provided or auto-detected
|
|
44
|
+
this.storageAdapter = config.storageAdapter || createStorageAdapter();
|
|
45
|
+
// Initialize the authentication flow
|
|
46
|
+
void this.initializeAuth();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Add an event listener for authentication state changes
|
|
50
|
+
* @param type the type of the event
|
|
51
|
+
* @param listener the listener to add
|
|
52
|
+
* @param options options for the event listener
|
|
53
|
+
* @param options.signal an optional AbortSignal to abort the event listener
|
|
54
|
+
*/
|
|
55
|
+
addEventListener(type, listener, options) {
|
|
56
|
+
this.events.addEventListener(type, listener, options);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Remove an event listener
|
|
60
|
+
* @param type the type of the event
|
|
61
|
+
* @param listener the listener to remove
|
|
62
|
+
*/
|
|
63
|
+
removeEventListener(type, listener) {
|
|
64
|
+
this.events.removeEventListener(type, listener);
|
|
65
|
+
}
|
|
66
|
+
async waitForAuth() {
|
|
67
|
+
if (this.authState === "ready") {
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
if (this.authState === "error") {
|
|
71
|
+
throw new Error("Authentication failed");
|
|
72
|
+
}
|
|
73
|
+
// Wait for the current auth promise to resolve
|
|
74
|
+
if (this.authPromise) {
|
|
75
|
+
return this.authPromise;
|
|
76
|
+
}
|
|
77
|
+
throw new Error("Authentication not initialized");
|
|
78
|
+
}
|
|
79
|
+
async updateExternalJwt(jwt) {
|
|
80
|
+
if (this.config.externalJwt === jwt)
|
|
81
|
+
return;
|
|
82
|
+
this.config.externalJwt = jwt;
|
|
83
|
+
this.processedJwt = Symbol("updating");
|
|
84
|
+
await this.performAuthFlow();
|
|
85
|
+
}
|
|
86
|
+
get state() {
|
|
87
|
+
return this.authState;
|
|
88
|
+
}
|
|
89
|
+
async getAuthHeaders() {
|
|
90
|
+
await this.waitForAuth();
|
|
91
|
+
if (!this.supabaseClient) {
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
const session = await this.supabaseClient.getSession();
|
|
95
|
+
if (!session.data.session) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
const { access_token } = session.data.session;
|
|
99
|
+
const headers = {};
|
|
100
|
+
if (access_token) {
|
|
101
|
+
headers["sp-access-token"] = access_token;
|
|
102
|
+
}
|
|
103
|
+
return headers;
|
|
104
|
+
}
|
|
105
|
+
async clearStorage() {
|
|
106
|
+
try {
|
|
107
|
+
await this.storageAdapter.removeItem(TOKEN_STORAGE_KEY);
|
|
108
|
+
await this.storageAdapter.removeItem(CHECK_KEY);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Ignore storage errors
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async logout() {
|
|
115
|
+
if (this.supabaseClient) {
|
|
116
|
+
await this.supabaseClient.signOut({ scope: "local" });
|
|
117
|
+
}
|
|
118
|
+
await this.clearStorage();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Public API methods that automatically wait for authentication
|
|
122
|
+
*/
|
|
123
|
+
api = {
|
|
124
|
+
getRecentFlows: async (params = {}) => {
|
|
125
|
+
await this.waitForAuth();
|
|
126
|
+
if (!this.internalApiClient)
|
|
127
|
+
throw new Error("API client not ready");
|
|
128
|
+
const { data, error, response } = await this.internalApiClient.GET(RetrieveRecentFlows.path, {
|
|
129
|
+
params: {
|
|
130
|
+
query: {
|
|
131
|
+
limit: params.limit ?? 10,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
if (error) {
|
|
136
|
+
throw new ApiError(error.error, response, {
|
|
137
|
+
status: response.status,
|
|
138
|
+
statusText: response.statusText,
|
|
139
|
+
url: response.url,
|
|
140
|
+
method: "GET",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return data;
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated Use `createFlow` instead.
|
|
147
|
+
* @param request the user request
|
|
148
|
+
* @returns the id of the created flow
|
|
149
|
+
*/
|
|
150
|
+
startFlow: async (request) => {
|
|
151
|
+
await this.waitForAuth();
|
|
152
|
+
if (!this.internalApiClient)
|
|
153
|
+
throw new Error("API client not ready");
|
|
154
|
+
if ("query" in request) {
|
|
155
|
+
const { data, response } = await this.internalApiClient.POST(RunEnd2EndFlowRoute.path, {
|
|
156
|
+
body: {
|
|
157
|
+
userQuery: request.query,
|
|
158
|
+
isNewAnalysisGoal: true,
|
|
159
|
+
difficultyLevel: "complex",
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
if (!data || data.status === "error") {
|
|
163
|
+
throw new ApiError(data?.error ?? "Failed to start flow", response, {
|
|
164
|
+
status: response.status,
|
|
165
|
+
statusText: response.statusText,
|
|
166
|
+
url: response.url,
|
|
167
|
+
method: "POST",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return data.flowId;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const { triggerId, variables } = request;
|
|
174
|
+
const { data, response } = await this.internalApiClient.POST(TriggerFlow.path, {
|
|
175
|
+
body: {
|
|
176
|
+
triggerId,
|
|
177
|
+
variables,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
if (!data || data.status === "error") {
|
|
181
|
+
throw new ApiError(data?.error ?? "Failed to trigger flow", response, {
|
|
182
|
+
status: response.status,
|
|
183
|
+
statusText: response.statusText,
|
|
184
|
+
url: response.url,
|
|
185
|
+
method: "POST",
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return data.flowId;
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
createFlow: async (request) => {
|
|
192
|
+
await this.waitForAuth();
|
|
193
|
+
if (!this.internalApiClient)
|
|
194
|
+
throw new Error("API client not ready");
|
|
195
|
+
if ("query" in request) {
|
|
196
|
+
const { data, error, response } = await this.internalApiClient.POST(CreateFlow.path, {
|
|
197
|
+
body: {
|
|
198
|
+
userQuery: request.query,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
if (error) {
|
|
202
|
+
throw new ApiError(error.error, response, {
|
|
203
|
+
status: response.status,
|
|
204
|
+
statusText: response.statusText,
|
|
205
|
+
url: response.url,
|
|
206
|
+
method: "POST",
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return { flowId: data.flowId };
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const { triggerId, variables } = request;
|
|
213
|
+
const { data, response } = await this.internalApiClient.POST(TriggerFlow.path, {
|
|
214
|
+
body: {
|
|
215
|
+
triggerId,
|
|
216
|
+
variables,
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
if (!data || data.status === "error") {
|
|
220
|
+
throw new ApiError(data?.error ?? "Failed to trigger flow", response, {
|
|
221
|
+
status: response.status,
|
|
222
|
+
statusText: response.statusText,
|
|
223
|
+
url: response.url,
|
|
224
|
+
method: "POST",
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return { flowId: data.flowId };
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
getDashboard: async (dashboardId) => {
|
|
231
|
+
await this.waitForAuth();
|
|
232
|
+
if (!this.internalApiClient)
|
|
233
|
+
throw new Error("API client not ready");
|
|
234
|
+
const { data, error, response } = await this.internalApiClient.GET(RetrieveDashboard.path, {
|
|
235
|
+
params: {
|
|
236
|
+
path: {
|
|
237
|
+
dashboard_id: dashboardId,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
if (error) {
|
|
242
|
+
throw new ApiError(error.error, response, {
|
|
243
|
+
status: response.status,
|
|
244
|
+
statusText: response.statusText,
|
|
245
|
+
url: response.url,
|
|
246
|
+
method: "GET",
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return data;
|
|
250
|
+
},
|
|
251
|
+
exportReportData: async (reportId, format = "blob") => {
|
|
252
|
+
await this.waitForAuth();
|
|
253
|
+
if (!this.internalApiClient)
|
|
254
|
+
throw new Error("API client not ready");
|
|
255
|
+
const { data, error, response } = await this.internalApiClient.GET(ExportReportData.path, {
|
|
256
|
+
params: {
|
|
257
|
+
path: {
|
|
258
|
+
report_id: String(reportId),
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
parseAs: format,
|
|
262
|
+
});
|
|
263
|
+
if (error) {
|
|
264
|
+
throw new ApiError(error.error, response, {
|
|
265
|
+
status: response.status,
|
|
266
|
+
statusText: response.statusText,
|
|
267
|
+
url: response.url,
|
|
268
|
+
method: "GET",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
272
|
+
const filename = contentDisposition
|
|
273
|
+
? contentDisposition.split("filename=")[1]?.replace(/"/g, "") ||
|
|
274
|
+
`mm-export-${reportId}.csv`
|
|
275
|
+
: `mm-export-${reportId}.csv`;
|
|
276
|
+
return { filename: filename, data: data };
|
|
277
|
+
},
|
|
278
|
+
generateContextualInsight: async (payload) => {
|
|
279
|
+
await this.waitForAuth();
|
|
280
|
+
if (!this.internalApiClient)
|
|
281
|
+
throw new Error("API client not ready");
|
|
282
|
+
const { data, error, response } = await this.internalApiClient.POST(GenerateInsight.path, {
|
|
283
|
+
body: {
|
|
284
|
+
selected_filter_value: payload.selectedFilterValue,
|
|
285
|
+
custom_id: payload.customId,
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
if (error) {
|
|
289
|
+
throw new ApiError(error.error, response, {
|
|
290
|
+
status: response.status,
|
|
291
|
+
statusText: response.statusText,
|
|
292
|
+
url: response.url,
|
|
293
|
+
method: "POST",
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return data;
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Initialize authentication flow
|
|
301
|
+
*/
|
|
302
|
+
async initializeAuth() {
|
|
303
|
+
this.authPromise = this.performAuthFlow();
|
|
304
|
+
try {
|
|
305
|
+
await this.authPromise;
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.error("Failed to initialize authentication:", error);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Perform the complete authentication flow
|
|
313
|
+
*/
|
|
314
|
+
async performAuthFlow() {
|
|
315
|
+
try {
|
|
316
|
+
this.setState("initializing");
|
|
317
|
+
// 1. Get API information first (this can probably be cached, the client is already cached)
|
|
318
|
+
const apiInfo = await this.getApiInformation();
|
|
319
|
+
// 2. Initialize Supabase client (this is cached already)
|
|
320
|
+
this.initializeSupabaseClient(apiInfo.anonKey, apiInfo.apiUrl);
|
|
321
|
+
// 3. Initialize API client
|
|
322
|
+
this.initializeApiClient();
|
|
323
|
+
// 4. Check for existing session or exchange token
|
|
324
|
+
await this.handleAuthentication();
|
|
325
|
+
// 5. Update local storage with the new JWT
|
|
326
|
+
if (this.config.externalJwt) {
|
|
327
|
+
await this.saveCheckKey(this.config.externalJwt, this.config.apiKey);
|
|
328
|
+
}
|
|
329
|
+
this.setState("ready");
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
console.error("Authentication flow failed:", error);
|
|
333
|
+
this.setState("error");
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async getApiInformation() {
|
|
338
|
+
if (!this.noAuthApiClient || !this.authApiResponse) {
|
|
339
|
+
this.noAuthApiClient = getPublicApiClient(this.config.apiUrl, this.config.apiKey);
|
|
340
|
+
const { data } = await this.noAuthApiClient.GET(GetApiInformation.path, {
|
|
341
|
+
params: {
|
|
342
|
+
query: {
|
|
343
|
+
apiKey: this.config.apiKey,
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
if (!data) {
|
|
348
|
+
throw new Error("Failed to fetch API information");
|
|
349
|
+
}
|
|
350
|
+
this.authApiResponse = data;
|
|
351
|
+
}
|
|
352
|
+
return this.authApiResponse;
|
|
353
|
+
}
|
|
354
|
+
initializeSupabaseClient(anonKey, apiUrl) {
|
|
355
|
+
if (!this.supabaseClient) {
|
|
356
|
+
this.supabaseClient = new GoTrueClient({
|
|
357
|
+
url: `${apiUrl}/auth/v1`,
|
|
358
|
+
storageKey: TOKEN_STORAGE_KEY,
|
|
359
|
+
headers: {
|
|
360
|
+
apiKey: anonKey,
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
// Set up auth state change listener with token refresh handling
|
|
364
|
+
this.supabaseClient.onAuthStateChange((event, session) => {
|
|
365
|
+
console.debug("Supabase auth state change:", event, !!session);
|
|
366
|
+
// Handle token refresh
|
|
367
|
+
if (event === "TOKEN_REFRESHED" && session) {
|
|
368
|
+
console.debug("Token refreshed successfully");
|
|
369
|
+
this.setState("ready");
|
|
370
|
+
}
|
|
371
|
+
else if (event === "SIGNED_OUT") {
|
|
372
|
+
console.debug("User signed out");
|
|
373
|
+
void this.clearStorage();
|
|
374
|
+
this.setState("initializing");
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/* This method always waits for authentication to complete before returning the client */
|
|
380
|
+
async client() {
|
|
381
|
+
await this.waitForAuth();
|
|
382
|
+
if (this.authState === "ready") {
|
|
383
|
+
if (!this.internalApiClient) {
|
|
384
|
+
throw new Error("Client is ready but API client not available. This should never happen");
|
|
385
|
+
}
|
|
386
|
+
return this.internalApiClient;
|
|
387
|
+
}
|
|
388
|
+
throw new Error(`Client is not available in auth state: ${this.authState}`);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Initialize the API client with Supabase headers
|
|
392
|
+
*/
|
|
393
|
+
initializeApiClient() {
|
|
394
|
+
this.internalApiClient = createApiClient({ baseUrl: this.config.apiUrl });
|
|
395
|
+
this.internalApiClient.use(throwOnError);
|
|
396
|
+
this.internalApiClient.use(this.createSupabaseHeaderMiddleware());
|
|
397
|
+
this.internalApiClient.use(addVersionHeader(MM_CLIENT_VERSION));
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Handle the authentication logic (check session or exchange token)
|
|
401
|
+
*/
|
|
402
|
+
async handleAuthentication() {
|
|
403
|
+
if (!this.supabaseClient) {
|
|
404
|
+
throw new Error("Supabase client not initialized");
|
|
405
|
+
}
|
|
406
|
+
// Skip if we've already processed this JWT
|
|
407
|
+
if (this.processedJwt === this.config.externalJwt) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
const { data, error } = await this.supabaseClient.getSession();
|
|
412
|
+
if (error) {
|
|
413
|
+
console.error("Error getting session:", error);
|
|
414
|
+
this.processedJwt = this.config.externalJwt || "";
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const isCheckValid = await this.compareCheckKey(this.config.externalJwt ?? "", this.config.apiKey);
|
|
418
|
+
if (data.session && this.config.externalJwt && isCheckValid) {
|
|
419
|
+
console.debug("Session found, authentication ready");
|
|
420
|
+
this.processedJwt = this.config.externalJwt || "";
|
|
421
|
+
}
|
|
422
|
+
else if (this.config.externalJwt) {
|
|
423
|
+
console.debug("No session found, exchanging external JWT");
|
|
424
|
+
await this.clearCheckKey();
|
|
425
|
+
await this.exchangeExternalToken();
|
|
426
|
+
this.processedJwt = this.config.externalJwt;
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
console.debug("No session and no external JWT provided");
|
|
430
|
+
this.processedJwt = this.config.externalJwt || "";
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
console.error("Unhandled error during authentication:", error);
|
|
435
|
+
this.processedJwt = this.config.externalJwt || "";
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Exchange external JWT for Supabase tokens
|
|
441
|
+
*/
|
|
442
|
+
async exchangeExternalToken() {
|
|
443
|
+
if (!this.noAuthApiClient ||
|
|
444
|
+
!this.supabaseClient ||
|
|
445
|
+
!this.config.externalJwt) {
|
|
446
|
+
throw new Error("Required clients or JWT not available for token exchange");
|
|
447
|
+
}
|
|
448
|
+
const { data } = await this.noAuthApiClient.POST(ExchangeExternalToken.path, {
|
|
449
|
+
body: {
|
|
450
|
+
apiKey: this.config.apiKey,
|
|
451
|
+
externalJWT: this.config.externalJwt,
|
|
452
|
+
},
|
|
453
|
+
headers: this.config.additionalHeaders || {},
|
|
454
|
+
});
|
|
455
|
+
if (!data) {
|
|
456
|
+
throw new Error("Failed to exchange tokens");
|
|
457
|
+
}
|
|
458
|
+
// Set the session in Supabase
|
|
459
|
+
await this.supabaseClient.setSession({
|
|
460
|
+
access_token: data.accessToken,
|
|
461
|
+
refresh_token: data.refreshToken,
|
|
462
|
+
});
|
|
463
|
+
console.debug("Token exchange successful, session set");
|
|
464
|
+
}
|
|
465
|
+
createSupabaseHeaderMiddleware() {
|
|
466
|
+
const supabaseClient = this.supabaseClient;
|
|
467
|
+
return {
|
|
468
|
+
async onRequest({ request }) {
|
|
469
|
+
if (!supabaseClient) {
|
|
470
|
+
return request;
|
|
471
|
+
}
|
|
472
|
+
const session = await supabaseClient.getSession();
|
|
473
|
+
if (!session.data.session) {
|
|
474
|
+
return request;
|
|
475
|
+
}
|
|
476
|
+
const { access_token } = session.data.session;
|
|
477
|
+
if (access_token) {
|
|
478
|
+
request.headers.set("sp-access-token", access_token);
|
|
479
|
+
}
|
|
480
|
+
return request;
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
setState(state) {
|
|
485
|
+
this.authState = state;
|
|
486
|
+
this.events.dispatch("authStateChange", state);
|
|
487
|
+
}
|
|
488
|
+
encodeCheckKey(externalJwt, apiKey) {
|
|
489
|
+
return hashString(JSON.stringify({
|
|
490
|
+
externalJwt,
|
|
491
|
+
apiKey,
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
async saveCheckKey(externalJwt, apiKey) {
|
|
495
|
+
const encodedKey = this.encodeCheckKey(externalJwt, apiKey);
|
|
496
|
+
await this.storageAdapter.setItem(CHECK_KEY, encodedKey);
|
|
497
|
+
}
|
|
498
|
+
async compareCheckKey(externalJwt, apiKey) {
|
|
499
|
+
const storedKey = await this.storageAdapter.getItem(CHECK_KEY);
|
|
500
|
+
if (!storedKey)
|
|
501
|
+
return false;
|
|
502
|
+
const newValue = this.encodeCheckKey(externalJwt, apiKey);
|
|
503
|
+
return storedKey === newValue;
|
|
504
|
+
}
|
|
505
|
+
async clearCheckKey() {
|
|
506
|
+
await this.storageAdapter.removeItem(CHECK_KEY);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
//# sourceMappingURL=MageMetricsClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MageMetricsClient.js","sourceRoot":"","sources":["../../../src/core/MageMetricsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,YAAY,GACb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,eAAe,GAEhB,MAAM,8DAA8D,CAAC;AACtE,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAElB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAC;AACrF,OAAO,EACL,UAAU,E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KAAK,QAAQ,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuthState } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Event types using discriminated union for type safety and extensibility
|
|
4
|
+
*/
|
|
5
|
+
export type MageMetricsEvent = {
|
|
6
|
+
type: "authStateChange";
|
|
7
|
+
detail: AuthState;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Event listener function type
|
|
11
|
+
*/
|
|
12
|
+
export type MageMetricsEventListener<T extends MageMetricsEvent = MageMetricsEvent> = (event: T) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Simple event emitter for MageMetrics client.
|
|
15
|
+
* Uses discriminated unions for type-safe events.
|
|
16
|
+
*/
|
|
17
|
+
export declare class MageMetricsEventEmitter {
|
|
18
|
+
private listeners;
|
|
19
|
+
addEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>, options?: {
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
}): void;
|
|
22
|
+
removeEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>): void;
|
|
23
|
+
dispatch<T extends MageMetricsEvent>(type: T["type"], detail: T["detail"]): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=MageMetricsEventEmitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MageMetricsEventEmitter.d.ts","sourceRoot":"","sources":["../../../src/core/MageMetricsEventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAGF;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAClC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,IAC3C,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEvB;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,SAAS,CAAyD;IAE1E,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EACzC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EACf,QAAQ,EAAE,wBAAwB,CAAC,CAAC,CAAC,EACrC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACjC,IAAI;IAsBP,mBAAmB,CAAC,CAAC,SAAS,gBAAgB,EAC5C,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EACf,QAAQ,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACpC,IAAI;IAUP,QAAQ,CAAC,CAAC,SAAS,gBAAgB,EACjC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EACf,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,GAClB,IAAI;CAcR"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple event emitter for MageMetrics client.
|
|
3
|
+
* Uses discriminated unions for type-safe events.
|
|
4
|
+
*/
|
|
5
|
+
export class MageMetricsEventEmitter {
|
|
6
|
+
listeners = new Map();
|
|
7
|
+
addEventListener(type, listener, options) {
|
|
8
|
+
if (!this.listeners.has(type)) {
|
|
9
|
+
this.listeners.set(type, new Set());
|
|
10
|
+
}
|
|
11
|
+
// Handle AbortSignal for compatibility
|
|
12
|
+
if (options?.signal) {
|
|
13
|
+
if (options.signal.aborted) {
|
|
14
|
+
return; // Don't add if already aborted
|
|
15
|
+
}
|
|
16
|
+
// Set up abort handler
|
|
17
|
+
const abortHandler = () => {
|
|
18
|
+
this.removeEventListener(type, listener);
|
|
19
|
+
};
|
|
20
|
+
options.signal.addEventListener("abort", abortHandler, { once: true });
|
|
21
|
+
}
|
|
22
|
+
this.listeners.get(type).add(listener);
|
|
23
|
+
}
|
|
24
|
+
removeEventListener(type, listener) {
|
|
25
|
+
const typeListeners = this.listeners.get(type);
|
|
26
|
+
if (typeListeners) {
|
|
27
|
+
typeListeners.delete(listener);
|
|
28
|
+
if (typeListeners.size === 0) {
|
|
29
|
+
this.listeners.delete(type);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
dispatch(type, detail) {
|
|
34
|
+
const typeListeners = this.listeners.get(type);
|
|
35
|
+
if (typeListeners) {
|
|
36
|
+
const event = { type, detail };
|
|
37
|
+
typeListeners.forEach((listener) => {
|
|
38
|
+
try {
|
|
39
|
+
listener(event);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(`Error in event listener for "${type}":`, error);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=MageMetricsEventEmitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MageMetricsEventEmitter.js","sourceRoot":"","sources":["../../../src/core/MageMetricsEventEmitter.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAC1B,SAAS,GAA+C,IAAI,GAAG,EAAE,CAAC;IAE1E,gBAAgB,CACd,IAAe,EACf,QAAqC,EACrC,OAAkC;QAElC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACtC,CAAC;QAED,uCAAuC;QACvC,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YACpB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC3B,OAAO,CAAC,+BAA+B;YACzC,CAA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 @@
|
|
|
1
|
+
import type { AsyncStorage } from "#adapters/storage/interface";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the MageMetricsClient
|
|
4
|
+
*/
|
|
5
|
+
export interface MageMetricsClientConfig {
|
|
6
|
+
apiUrl: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
externalJwt?: string;
|
|
9
|
+
additionalHeaders?: Record<string, string>;
|
|
10
|
+
storageAdapter?: AsyncStorage;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Authentication states
|
|
14
|
+
*/
|
|
15
|
+
export type AuthState = "initializing" | "ready" | "error";
|
|
16
|
+
/**
|
|
17
|
+
* Parameters for starting a flow
|
|
18
|
+
*/
|
|
19
|
+
export type StartFlowParam = {
|
|
20
|
+
query: string;
|
|
21
|
+
} | {
|
|
22
|
+
triggerId: string;
|
|
23
|
+
variables: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Parameters for generating contextual insights
|
|
27
|
+
*/
|
|
28
|
+
export type GenerateInsightParam = {
|
|
29
|
+
selectedFilterValue: string;
|
|
30
|
+
customId: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Token storage keys
|
|
34
|
+
*/
|
|
35
|
+
export declare const TOKEN_STORAGE_KEY = "mm-ai-sp-token";
|
|
36
|
+
export declare const CHECK_KEY = "mm-ai-check-key";
|
|
37
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAClD,eAAO,MAAM,SAAS,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAiCA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAClD,MAAM,CAAC,MAAM,SAAS,GAAG,iBAAiB,CAAC"}
|