@magemetrics/core 0.0.59 → 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/dist/index.d.ts +4279 -0
- package/dist/index.js +2884 -0
- package/dist/index.js.map +1 -0
- package/package.json +12 -9
- package/dist/package.json +0 -59
- package/dist/src/adapters/storage/browser.d.ts +0 -11
- package/dist/src/adapters/storage/browser.d.ts.map +0 -1
- package/dist/src/adapters/storage/browser.js +0 -37
- package/dist/src/adapters/storage/browser.js.map +0 -1
- package/dist/src/adapters/storage/factory.d.ts +0 -8
- package/dist/src/adapters/storage/factory.d.ts.map +0 -1
- package/dist/src/adapters/storage/factory.js +0 -24
- package/dist/src/adapters/storage/factory.js.map +0 -1
- package/dist/src/adapters/storage/interface.d.ts +0 -26
- package/dist/src/adapters/storage/interface.d.ts.map +0 -1
- package/dist/src/adapters/storage/interface.js +0 -1
- package/dist/src/adapters/storage/interface.js.map +0 -1
- package/dist/src/adapters/storage/memory.d.ts +0 -11
- package/dist/src/adapters/storage/memory.d.ts.map +0 -1
- package/dist/src/adapters/storage/memory.js +0 -20
- package/dist/src/adapters/storage/memory.js.map +0 -1
- package/dist/src/core/MageMetricsClient.d.ts +0 -103
- package/dist/src/core/MageMetricsClient.d.ts.map +0 -1
- package/dist/src/core/MageMetricsClient.js +0 -509
- package/dist/src/core/MageMetricsClient.js.map +0 -1
- package/dist/src/core/MageMetricsEventEmitter.d.ts +0 -25
- package/dist/src/core/MageMetricsEventEmitter.d.ts.map +0 -1
- package/dist/src/core/MageMetricsEventEmitter.js +0 -48
- package/dist/src/core/MageMetricsEventEmitter.js.map +0 -1
- package/dist/src/core/types.d.ts +0 -37
- package/dist/src/core/types.d.ts.map +0 -1
- package/dist/src/core/types.js +0 -6
- package/dist/src/core/types.js.map +0 -1
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -7
- package/dist/src/index.js.map +0 -1
- package/dist/src/utils/hash.d.ts +0 -8
- package/dist/src/utils/hash.d.ts.map +0 -1
- package/dist/src/utils/hash.js +0 -16
- package/dist/src/utils/hash.js.map +0 -1
- package/dist/src/utils/platform.d.ts +0 -10
- package/dist/src/utils/platform.d.ts.map +0 -1
- package/dist/src/utils/platform.js +0 -25
- package/dist/src/utils/platform.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magemetrics/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "MageMetrics client library",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"imports": {
|
|
@@ -19,22 +19,25 @@
|
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
21
|
"@magemetrics/source": "./src/index.ts",
|
|
22
|
-
"types": "./dist/
|
|
23
|
-
"react-native": "./dist/
|
|
24
|
-
"browser": "./dist/
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"react-native": "./dist/index.js",
|
|
24
|
+
"browser": "./dist/index.js",
|
|
25
25
|
"node": {
|
|
26
|
-
"import": "./dist/
|
|
27
|
-
"require": "./dist/
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.js"
|
|
28
28
|
},
|
|
29
|
-
"default": "./dist/
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist/"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@noble/hashes": "^2.0.0",
|
|
36
37
|
"@supabase/auth-js": "^2.71.1",
|
|
38
|
+
"ai": "5.0.48",
|
|
39
|
+
"dayjs": "^1.11.18",
|
|
37
40
|
"openapi-fetch": "^0.14.0",
|
|
38
|
-
"
|
|
41
|
+
"zod": "^3.25.76"
|
|
39
42
|
}
|
|
40
43
|
}
|
package/dist/package.json
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@magemetrics/core",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.0.59",
|
|
5
|
-
"description": "Universal MageMetrics client library for browser, Node.js, and React Native",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "tsc --watch",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"typecheck": "tsc --noEmit",
|
|
10
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
11
|
-
"lint": "sh -c 'cd ../../ && pnpm exec eslint --report-unused-disable-directives packages/core'",
|
|
12
|
-
"lint:fix": "sh -c 'cd ../../ && pnpm exec eslint packages/core --fix'",
|
|
13
|
-
"format": "prettier --check .",
|
|
14
|
-
"format:fix": "prettier --write ."
|
|
15
|
-
},
|
|
16
|
-
"main": "./dist/index.js",
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"imports": {
|
|
19
|
-
"#*": {
|
|
20
|
-
"types": [
|
|
21
|
-
"./src/*.ts",
|
|
22
|
-
"./src/*"
|
|
23
|
-
],
|
|
24
|
-
"default": [
|
|
25
|
-
"./src/*"
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"exports": {
|
|
30
|
-
".": {
|
|
31
|
-
"@magemetrics/source": "./src/index.ts",
|
|
32
|
-
"types": "./dist/src/index.d.ts",
|
|
33
|
-
"react-native": "./dist/src/index.js",
|
|
34
|
-
"browser": "./dist/src/index.js",
|
|
35
|
-
"node": {
|
|
36
|
-
"import": "./dist/src/index.js",
|
|
37
|
-
"require": "./dist/src/index.js"
|
|
38
|
-
},
|
|
39
|
-
"default": "./dist/src/index.js"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"files": [
|
|
43
|
-
"dist/"
|
|
44
|
-
],
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@mm/shared": "workspace:*",
|
|
47
|
-
"@supabase/auth-js": "^2.71.1",
|
|
48
|
-
"openapi-fetch": "^0.14.0",
|
|
49
|
-
"@noble/hashes": "^1.3.0"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@mm/tsconfig": "workspace:*",
|
|
53
|
-
"@types/node": "^22.16.5",
|
|
54
|
-
"type-fest": "^4.41.0",
|
|
55
|
-
"vite": "^7.1.3",
|
|
56
|
-
"vite-tsconfig-paths": "^5.1.4",
|
|
57
|
-
"vitest": "^3.2.4"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AsyncStorage } from "./interface";
|
|
2
|
-
/**
|
|
3
|
-
* Browser localStorage adapter with async interface.
|
|
4
|
-
* Wraps the synchronous localStorage API with async methods for consistency.
|
|
5
|
-
*/
|
|
6
|
-
export declare class BrowserStorageAdapter implements AsyncStorage {
|
|
7
|
-
getItem(key: string): Promise<string | null>;
|
|
8
|
-
setItem(key: string, value: string): Promise<void>;
|
|
9
|
-
removeItem(key: string): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/adapters/storage/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,YAAY;IAElD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAa5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAalD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAW7C"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser localStorage adapter with async interface.
|
|
3
|
-
* Wraps the synchronous localStorage API with async methods for consistency.
|
|
4
|
-
*/
|
|
5
|
-
export class BrowserStorageAdapter {
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
7
|
-
async getItem(key) {
|
|
8
|
-
try {
|
|
9
|
-
return localStorage.getItem(key);
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.warn("BrowserStorageAdapter: Failed to get item from localStorage", error);
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
17
|
-
async setItem(key, value) {
|
|
18
|
-
try {
|
|
19
|
-
localStorage.setItem(key, value);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.warn("BrowserStorageAdapter: Failed to set item in localStorage", error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
27
|
-
async removeItem(key) {
|
|
28
|
-
try {
|
|
29
|
-
localStorage.removeItem(key);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.warn("BrowserStorageAdapter: Failed to remove item from localStorage", error);
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../../src/adapters/storage/browser.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAChC,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,IAAI,CAAC;YACH,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CACV,6DAA6D,EAC7D,KAAK,CACN,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;QACtC,IAAI,CAAC;YACH,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CACV,2DAA2D,EAC3D,KAAK,CACN,CAAC;YACF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,CAAC;YACH,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CACV,gEAAgE,EAChE,KAAK,CACN,CAAC;YACF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AsyncStorage } from "./interface";
|
|
2
|
-
/**
|
|
3
|
-
* Create the appropriate storage adapter based on the current platform.
|
|
4
|
-
* For React Native, you must provide the AsyncStorage instance.
|
|
5
|
-
* @returns The appropriate storage adapter for the current platform
|
|
6
|
-
*/
|
|
7
|
-
export declare const createStorageAdapter: () => AsyncStorage;
|
|
8
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/adapters/storage/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,QAAO,YAiBvC,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getPlatform } from "#utils/platform";
|
|
2
|
-
import { BrowserStorageAdapter } from "./browser";
|
|
3
|
-
import { MemoryStorageAdapter } from "./memory";
|
|
4
|
-
/**
|
|
5
|
-
* Create the appropriate storage adapter based on the current platform.
|
|
6
|
-
* For React Native, you must provide the AsyncStorage instance.
|
|
7
|
-
* @returns The appropriate storage adapter for the current platform
|
|
8
|
-
*/
|
|
9
|
-
export const createStorageAdapter = () => {
|
|
10
|
-
const platform = getPlatform();
|
|
11
|
-
switch (platform) {
|
|
12
|
-
case "browser":
|
|
13
|
-
return new BrowserStorageAdapter();
|
|
14
|
-
case "node":
|
|
15
|
-
return new MemoryStorageAdapter();
|
|
16
|
-
case "react-native":
|
|
17
|
-
throw new Error("Please provide AsyncStorage for React Native");
|
|
18
|
-
case "unknown":
|
|
19
|
-
default:
|
|
20
|
-
console.warn(`Unknown platform detected: ${platform}. Defaulting to in memory storage.`);
|
|
21
|
-
return new MemoryStorageAdapter();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/adapters/storage/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAiB,EAAE;IACrD,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,IAAI,qBAAqB,EAAE,CAAC;QACrC,KAAK,MAAM;YACT,OAAO,IAAI,oBAAoB,EAAE,CAAC;QACpC,KAAK,cAAc;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,KAAK,SAAS,CAAC;QACf;YACE,OAAO,CAAC,IAAI,CACV,8BAA8B,QAAQ,oCAAoC,CAC3E,CAAC;YACF,OAAO,IAAI,oBAAoB,EAAE,CAAC;IACtC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Universal storage adapter interface for cross-platform compatibility.
|
|
3
|
-
* All operations are async to accommodate different storage mechanisms.
|
|
4
|
-
*/
|
|
5
|
-
export interface AsyncStorage {
|
|
6
|
-
/**
|
|
7
|
-
* Retrieve an item from storage
|
|
8
|
-
* @param key - The storage key
|
|
9
|
-
* @returns Promise resolving to the stored value or null if not found
|
|
10
|
-
*/
|
|
11
|
-
getItem(key: string): Promise<string | null>;
|
|
12
|
-
/**
|
|
13
|
-
* Store an item in storage
|
|
14
|
-
* @param key - The storage key
|
|
15
|
-
* @param value - The value to store (must be a string)
|
|
16
|
-
* @returns Promise resolving when storage is complete
|
|
17
|
-
*/
|
|
18
|
-
setItem(key: string, value: string): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Remove an item from storage
|
|
21
|
-
* @param key - The storage key
|
|
22
|
-
* @returns Promise resolving when removal is complete
|
|
23
|
-
*/
|
|
24
|
-
removeItem(key: string): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/adapters/storage/interface.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE7C;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD;;;;OAIG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=interface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../src/adapters/storage/interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AsyncStorage } from "./interface";
|
|
2
|
-
/**
|
|
3
|
-
* in-memory storage adapter.
|
|
4
|
-
*/
|
|
5
|
-
export declare class MemoryStorageAdapter implements AsyncStorage {
|
|
6
|
-
private storage;
|
|
7
|
-
getItem(key: string): Promise<string | null>;
|
|
8
|
-
setItem(key: string, value: string): Promise<void>;
|
|
9
|
-
removeItem(key: string): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/adapters/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,OAAO,CAA6B;IAGtC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAM5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* in-memory storage adapter.
|
|
3
|
-
*/
|
|
4
|
-
export class MemoryStorageAdapter {
|
|
5
|
-
storage = new Map();
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
7
|
-
async getItem(key) {
|
|
8
|
-
const value = this.storage.get(key);
|
|
9
|
-
return value !== undefined ? value : null;
|
|
10
|
-
}
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
12
|
-
async setItem(key, value) {
|
|
13
|
-
this.storage.set(key, value);
|
|
14
|
-
}
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
16
|
-
async removeItem(key) {
|
|
17
|
-
this.storage.delete(key);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=memory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../../src/adapters/storage/memory.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACvB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE5C,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { type ExtractInsightResponse } from "@mm/shared/endpoints/admin-console/contextualInsights.routes";
|
|
2
|
-
import type { InternalApiClient, NoAuthPaths } from "@mm/shared/types/api-types";
|
|
3
|
-
import { type Client } from "openapi-fetch";
|
|
4
|
-
import type { FrontendDashboard } from "@mm/shared/schemas/dashboard";
|
|
5
|
-
import type { FrontendRecentFlows } from "@mm/shared/schemas/flows";
|
|
6
|
-
import { type MageMetricsEvent, type MageMetricsEventListener } from "./MageMetricsEventEmitter";
|
|
7
|
-
import { type AuthState, type GenerateInsightParam, type MageMetricsClientConfig, type StartFlowParam } from "./types";
|
|
8
|
-
export declare const getPublicApiClient: (apiUrl: string, apiKey: string) => Client<NoAuthPaths>;
|
|
9
|
-
/**
|
|
10
|
-
* Core MageMetrics client that handles authentication lifecycle and provides
|
|
11
|
-
* a promise-based API that automatically waits for authentication to complete.
|
|
12
|
-
*
|
|
13
|
-
* This version uses composition instead of inheritance and pluggable storage adapters
|
|
14
|
-
* for cross-platform compatibility.
|
|
15
|
-
*/
|
|
16
|
-
export declare class MageMetricsClient {
|
|
17
|
-
private config;
|
|
18
|
-
private authState;
|
|
19
|
-
private supabaseClient;
|
|
20
|
-
private internalApiClient;
|
|
21
|
-
private noAuthApiClient;
|
|
22
|
-
private authApiResponse;
|
|
23
|
-
private authPromise;
|
|
24
|
-
private processedJwt;
|
|
25
|
-
private storageAdapter;
|
|
26
|
-
private events;
|
|
27
|
-
constructor(config: MageMetricsClientConfig);
|
|
28
|
-
/**
|
|
29
|
-
* Add an event listener for authentication state changes
|
|
30
|
-
* @param type the type of the event
|
|
31
|
-
* @param listener the listener to add
|
|
32
|
-
* @param options options for the event listener
|
|
33
|
-
* @param options.signal an optional AbortSignal to abort the event listener
|
|
34
|
-
*/
|
|
35
|
-
addEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>, options?: {
|
|
36
|
-
signal?: AbortSignal;
|
|
37
|
-
}): void;
|
|
38
|
-
/**
|
|
39
|
-
* Remove an event listener
|
|
40
|
-
* @param type the type of the event
|
|
41
|
-
* @param listener the listener to remove
|
|
42
|
-
*/
|
|
43
|
-
removeEventListener<T extends MageMetricsEvent>(type: T["type"], listener: MageMetricsEventListener<T>): void;
|
|
44
|
-
waitForAuth(): Promise<void>;
|
|
45
|
-
updateExternalJwt(jwt: string): Promise<void>;
|
|
46
|
-
get state(): AuthState;
|
|
47
|
-
getAuthHeaders(): Promise<Record<string, string>>;
|
|
48
|
-
private clearStorage;
|
|
49
|
-
logout(): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Public API methods that automatically wait for authentication
|
|
52
|
-
*/
|
|
53
|
-
api: {
|
|
54
|
-
getRecentFlows: (params?: {
|
|
55
|
-
limit?: number;
|
|
56
|
-
}) => Promise<FrontendRecentFlows[]>;
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Use `createFlow` instead.
|
|
59
|
-
* @param request the user request
|
|
60
|
-
* @returns the id of the created flow
|
|
61
|
-
*/
|
|
62
|
-
startFlow: (request: StartFlowParam) => Promise<string>;
|
|
63
|
-
createFlow: (request: StartFlowParam) => Promise<{
|
|
64
|
-
flowId: string;
|
|
65
|
-
}>;
|
|
66
|
-
getDashboard: (dashboardId: string) => Promise<FrontendDashboard>;
|
|
67
|
-
exportReportData: (reportId: number, format?: "text" | "blob") => Promise<{
|
|
68
|
-
filename: string;
|
|
69
|
-
data: Blob | string;
|
|
70
|
-
}>;
|
|
71
|
-
generateContextualInsight: (payload: GenerateInsightParam) => Promise<ExtractInsightResponse>;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Initialize authentication flow
|
|
75
|
-
*/
|
|
76
|
-
private initializeAuth;
|
|
77
|
-
/**
|
|
78
|
-
* Perform the complete authentication flow
|
|
79
|
-
*/
|
|
80
|
-
private performAuthFlow;
|
|
81
|
-
private getApiInformation;
|
|
82
|
-
private initializeSupabaseClient;
|
|
83
|
-
client(): Promise<InternalApiClient>;
|
|
84
|
-
/**
|
|
85
|
-
* Initialize the API client with Supabase headers
|
|
86
|
-
*/
|
|
87
|
-
private initializeApiClient;
|
|
88
|
-
/**
|
|
89
|
-
* Handle the authentication logic (check session or exchange token)
|
|
90
|
-
*/
|
|
91
|
-
private handleAuthentication;
|
|
92
|
-
/**
|
|
93
|
-
* Exchange external JWT for Supabase tokens
|
|
94
|
-
*/
|
|
95
|
-
private exchangeExternalToken;
|
|
96
|
-
private createSupabaseHeaderMiddleware;
|
|
97
|
-
private setState;
|
|
98
|
-
private encodeCheckKey;
|
|
99
|
-
saveCheckKey(externalJwt: string, apiKey: string): Promise<void>;
|
|
100
|
-
compareCheckKey(externalJwt: string, apiKey: string): Promise<boolean>;
|
|
101
|
-
clearCheckKey(): Promise<void>;
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=MageMetricsClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MageMetricsClient.d.ts","sourceRoot":"","sources":["../../../src/core/MageMetricsClient.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,8DAA8D,CAAC;AActE,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAwB,EAAE,KAAK,MAAM,EAAmB,MAAM,eAAe,CAAC;AAK9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAIjB,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,MAAM,EACd,QAAQ,MAAM,KACb,MAAM,CAAC,WAAW,CAMpB,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC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