@waniwani/sdk 0.0.4 → 0.0.5
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 +45 -65
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,82 +3,71 @@ declare class WaniWaniError extends Error {
|
|
|
3
3
|
constructor(message: string, status: number);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"openai/session"?: string;
|
|
11
|
-
"openai/userAgent"?: string;
|
|
12
|
-
"openai/locale"?: string;
|
|
13
|
-
"openai/userLocation"?: {
|
|
14
|
-
city?: string;
|
|
15
|
-
region?: string;
|
|
16
|
-
country?: string;
|
|
17
|
-
timezone?: string;
|
|
18
|
-
latitude?: string;
|
|
19
|
-
longitude?: string;
|
|
20
|
-
};
|
|
21
|
-
timezone_offset_minutes?: number;
|
|
6
|
+
type EventType = "tool.called" | "quote.requested" | "quote.succeeded" | "quote.failed" | "link.clicked" | "purchase.completed";
|
|
7
|
+
interface ToolCalledProperties {
|
|
8
|
+
name?: string;
|
|
9
|
+
type?: "pricing" | "product_info" | "availability" | "support" | "other";
|
|
22
10
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
region?: string;
|
|
27
|
-
country?: string;
|
|
28
|
-
timezone?: string;
|
|
11
|
+
interface QuoteSucceededProperties {
|
|
12
|
+
amount?: number;
|
|
13
|
+
currency?: string;
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
locale?: string;
|
|
37
|
-
location?: LocationInfo;
|
|
15
|
+
interface LinkClickedProperties {
|
|
16
|
+
url?: string;
|
|
17
|
+
}
|
|
18
|
+
interface PurchaseCompletedProperties {
|
|
19
|
+
amount?: number;
|
|
20
|
+
currency?: string;
|
|
38
21
|
}
|
|
39
|
-
type EventType = "session.started" | "tool.called" | "quote.requested" | "quote.succeeded" | "quote.failed" | "link.clicked" | "purchase.completed";
|
|
40
|
-
type ToolType = "pricing" | "product_info" | "availability" | "support" | "other";
|
|
41
22
|
interface BaseEvent {
|
|
42
23
|
/**
|
|
43
|
-
*
|
|
44
|
-
* (sessionId, userId, location, etc.). Can also include custom fields.
|
|
24
|
+
* Event type.
|
|
45
25
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* wani.track({
|
|
29
|
+
* event: 'tool.called',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
event: EventType;
|
|
34
|
+
/**
|
|
35
|
+
* Event properties.
|
|
49
36
|
*
|
|
50
37
|
* @example
|
|
51
38
|
* ```typescript
|
|
52
39
|
* wani.track({
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* meta: extra._meta,
|
|
40
|
+
* event: 'tool.called',
|
|
41
|
+
* properties: { name: 'search' },
|
|
56
42
|
* });
|
|
57
43
|
* ```
|
|
58
44
|
*/
|
|
45
|
+
properties?: Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* MCP request metadata passed through to the API.
|
|
48
|
+
*
|
|
49
|
+
* Location varies by MCP library:
|
|
50
|
+
* - `@vercel/mcp-handler`: `extra._meta`
|
|
51
|
+
* - `@modelcontextprotocol/sdk`: `request.params._meta`
|
|
52
|
+
*/
|
|
59
53
|
meta?: Record<string, unknown>;
|
|
60
54
|
}
|
|
61
55
|
type TrackEvent = ({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
eventType: "tool.called";
|
|
65
|
-
toolName?: string;
|
|
66
|
-
toolType?: ToolType;
|
|
56
|
+
event: "tool.called";
|
|
57
|
+
properties: ToolCalledProperties;
|
|
67
58
|
} & BaseEvent) | ({
|
|
68
|
-
|
|
59
|
+
event: "quote.requested";
|
|
69
60
|
} & BaseEvent) | ({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
quoteCurrency?: string;
|
|
61
|
+
event: "quote.succeeded";
|
|
62
|
+
properties: QuoteSucceededProperties;
|
|
73
63
|
} & BaseEvent) | ({
|
|
74
|
-
|
|
64
|
+
event: "quote.failed";
|
|
75
65
|
} & BaseEvent) | ({
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
event: "link.clicked";
|
|
67
|
+
properties: LinkClickedProperties;
|
|
78
68
|
} & BaseEvent) | ({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
purchaseCurrency?: string;
|
|
69
|
+
event: "purchase.completed";
|
|
70
|
+
properties: PurchaseCompletedProperties;
|
|
82
71
|
} & BaseEvent);
|
|
83
72
|
/**
|
|
84
73
|
* Tracking module methods for WaniWaniClient
|
|
@@ -120,15 +109,6 @@ interface WaniWaniConfig {
|
|
|
120
109
|
interface WaniWaniClient extends TrackingClient {
|
|
121
110
|
}
|
|
122
111
|
|
|
123
|
-
/**
|
|
124
|
-
* Detect which MCP provider sent the request based on metadata keys
|
|
125
|
-
*/
|
|
126
|
-
declare function detectProvider(meta: Record<string, unknown>): MCPProvider;
|
|
127
|
-
/**
|
|
128
|
-
* Extract normalized metadata from any MCP provider's metadata
|
|
129
|
-
*/
|
|
130
|
-
declare function extractMetadata(meta: Record<string, unknown>): NormalizedMeta;
|
|
131
|
-
|
|
132
112
|
/**
|
|
133
113
|
* Create a WaniWani SDK client
|
|
134
114
|
*
|
|
@@ -150,4 +130,4 @@ declare function extractMetadata(meta: Record<string, unknown>): NormalizedMeta;
|
|
|
150
130
|
*/
|
|
151
131
|
declare function waniwani(config?: WaniWaniConfig): WaniWaniClient;
|
|
152
132
|
|
|
153
|
-
export { type EventType, type
|
|
133
|
+
export { type EventType, type LinkClickedProperties, type PurchaseCompletedProperties, type QuoteSucceededProperties, type ToolCalledProperties, type TrackEvent, type WaniWaniClient, type WaniWaniConfig, WaniWaniError, waniwani };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n=class extends Error{constructor(e,o){super(e);this.status=o;this.name="WaniWaniError"}};function l(r){let{baseUrl:i,apiKey:e}=r;function o(){if(!e)throw new Error("WANIWANI_API_KEY is not set")}return{async track(p){try{o();let t=await fetch(`${i}/api/mcp/events`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(p)}),c=await t.json();if(!t.ok)throw new n(c.message??"Request failed",t.status);return{eventId:c.data.eventId}}catch(t){throw console.error("[WaniWani] Track error:",t),t}}}}function f(r){let i=r?.baseUrl??"https://app.waniwani.ai",e=r?.apiKey??process.env.WANIWANI_API_KEY;return{...l({baseUrl:i,apiKey:e})}}export{n as WaniWaniError,f as waniwani};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts","../src/tracking/
|
|
1
|
+
{"version":3,"sources":["../src/error.ts","../src/tracking/index.ts","../src/waniwani.ts"],"sourcesContent":["// WaniWani SDK - Errors\n\nexport class WaniWaniError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic status: number,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"WaniWaniError\";\n\t}\n}\n","// Tracking Module\n\nimport { WaniWaniError } from \"../error.js\";\nimport type { InternalConfig } from \"../types.js\";\nimport type { TrackEvent, TrackingClient } from \"./@types.js\";\n\n// Re-export types\nexport type {\n\tEventType,\n\tLinkClickedProperties,\n\tPurchaseCompletedProperties,\n\tQuoteSucceededProperties,\n\tToolCalledProperties,\n\tTrackEvent,\n\tTrackingClient,\n} from \"./@types.js\";\n\nexport function createTrackingClient(config: InternalConfig): TrackingClient {\n\tconst { baseUrl, apiKey } = config;\n\n\tfunction checkIfApiKeyIsSet() {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(\"WANIWANI_API_KEY is not set\");\n\t\t}\n\t}\n\n\treturn {\n\t\tasync track(event: TrackEvent): Promise<{ eventId: string }> {\n\t\t\ttry {\n\t\t\t\tcheckIfApiKeyIsSet();\n\n\t\t\t\tconst response = await fetch(`${baseUrl}/api/mcp/events`, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify(event),\n\t\t\t\t});\n\n\t\t\t\tconst data = await response.json();\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new WaniWaniError(\n\t\t\t\t\t\tdata.message ?? \"Request failed\",\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { eventId: data.data.eventId };\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\"[WaniWani] Track error:\", error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n","// WaniWani SDK - Main Entry\n\nimport { createTrackingClient } from \"./tracking/index.js\";\nimport type { WaniWaniClient, WaniWaniConfig } from \"./types.js\";\n\n/**\n * Create a WaniWani SDK client\n *\n * @param config - Configuration options\n * @returns A fully typed WaniWani client\n *\n * @example\n * ```typescript\n * import { waniwani } from \"@waniwani\";\n *\n * const client = waniwani({ apiKey: \"...\" });\n *\n * await client.track({\n * eventType: \"tool.called\",\n * sessionId: \"session-123\",\n * toolName: \"pricing\"\n * });\n * ```\n */\nexport function waniwani(config?: WaniWaniConfig): WaniWaniClient {\n\tconst baseUrl = config?.baseUrl ?? \"https://app.waniwani.ai\";\n\tconst apiKey = config?.apiKey ?? process.env.WANIWANI_API_KEY;\n\n\tconst internalConfig = { baseUrl, apiKey };\n\n\t// Compose client from modules\n\tconst tracking = createTrackingClient(internalConfig);\n\n\treturn {\n\t\t...tracking,\n\t\t// Future modules will be spread here\n\t\t// ...tools,\n\t};\n}\n"],"mappings":"AAEO,IAAMA,EAAN,cAA4B,KAAM,CACxC,YACCC,EACOC,EACN,CACD,MAAMD,CAAO,EAFN,YAAAC,EAGP,KAAK,KAAO,eACb,CACD,ECOO,SAASC,EAAqBC,EAAwC,CAC5E,GAAM,CAAE,QAAAC,EAAS,OAAAC,CAAO,EAAIF,EAE5B,SAASG,GAAqB,CAC7B,GAAI,CAACD,EACJ,MAAM,IAAI,MAAM,6BAA6B,CAE/C,CAEA,MAAO,CACN,MAAM,MAAME,EAAiD,CAC5D,GAAI,CACHD,EAAmB,EAEnB,IAAME,EAAW,MAAM,MAAM,GAAGJ,CAAO,kBAAmB,CACzD,OAAQ,OACR,QAAS,CACR,eAAgB,mBAChB,cAAe,UAAUC,CAAM,EAChC,EACA,KAAM,KAAK,UAAUE,CAAK,CAC3B,CAAC,EAEKE,EAAO,MAAMD,EAAS,KAAK,EAEjC,GAAI,CAACA,EAAS,GACb,MAAM,IAAIE,EACTD,EAAK,SAAW,iBAChBD,EAAS,MACV,EAGD,MAAO,CAAE,QAASC,EAAK,KAAK,OAAQ,CACrC,OAASE,EAAO,CACf,cAAQ,MAAM,0BAA2BA,CAAK,EACxCA,CACP,CACD,CACD,CACD,CChCO,SAASC,EAASC,EAAyC,CACjE,IAAMC,EAAUD,GAAQ,SAAW,0BAC7BE,EAASF,GAAQ,QAAU,QAAQ,IAAI,iBAO7C,MAAO,CACN,GAHgBG,EAHM,CAAE,QAAAF,EAAS,OAAAC,CAAO,CAGW,CAMpD,CACD","names":["WaniWaniError","message","status","createTrackingClient","config","baseUrl","apiKey","checkIfApiKeyIsSet","event","response","data","WaniWaniError","error","waniwani","config","baseUrl","apiKey","createTrackingClient"]}
|