@waniwani/sdk 0.0.3 → 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 +60 -31
- 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,54 +3,83 @@ declare class WaniWaniError extends Error {
|
|
|
3
3
|
constructor(message: string, status: number);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
type EventType = "
|
|
7
|
-
|
|
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";
|
|
10
|
+
}
|
|
11
|
+
interface QuoteSucceededProperties {
|
|
12
|
+
amount?: number;
|
|
13
|
+
currency?: string;
|
|
14
|
+
}
|
|
15
|
+
interface LinkClickedProperties {
|
|
16
|
+
url?: string;
|
|
17
|
+
}
|
|
18
|
+
interface PurchaseCompletedProperties {
|
|
19
|
+
amount?: number;
|
|
20
|
+
currency?: string;
|
|
21
|
+
}
|
|
8
22
|
interface BaseEvent {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Event type.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* wani.track({
|
|
29
|
+
* event: 'tool.called',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
event: EventType;
|
|
34
|
+
/**
|
|
35
|
+
* Event properties.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* wani.track({
|
|
40
|
+
* event: 'tool.called',
|
|
41
|
+
* properties: { name: 'search' },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
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
|
+
*/
|
|
53
|
+
meta?: Record<string, unknown>;
|
|
13
54
|
}
|
|
14
55
|
type TrackEvent = ({
|
|
15
|
-
|
|
56
|
+
event: "tool.called";
|
|
57
|
+
properties: ToolCalledProperties;
|
|
16
58
|
} & BaseEvent) | ({
|
|
17
|
-
|
|
18
|
-
toolName?: string;
|
|
19
|
-
toolType?: ToolType;
|
|
59
|
+
event: "quote.requested";
|
|
20
60
|
} & BaseEvent) | ({
|
|
21
|
-
|
|
61
|
+
event: "quote.succeeded";
|
|
62
|
+
properties: QuoteSucceededProperties;
|
|
22
63
|
} & BaseEvent) | ({
|
|
23
|
-
|
|
24
|
-
quoteAmount?: number;
|
|
25
|
-
quoteCurrency?: string;
|
|
64
|
+
event: "quote.failed";
|
|
26
65
|
} & BaseEvent) | ({
|
|
27
|
-
|
|
66
|
+
event: "link.clicked";
|
|
67
|
+
properties: LinkClickedProperties;
|
|
28
68
|
} & BaseEvent) | ({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} & BaseEvent) | ({
|
|
32
|
-
eventType: "purchase.completed";
|
|
33
|
-
purchaseAmount?: number;
|
|
34
|
-
purchaseCurrency?: string;
|
|
69
|
+
event: "purchase.completed";
|
|
70
|
+
properties: PurchaseCompletedProperties;
|
|
35
71
|
} & BaseEvent);
|
|
36
72
|
/**
|
|
37
73
|
* Tracking module methods for WaniWaniClient
|
|
38
74
|
*/
|
|
39
75
|
interface TrackingClient {
|
|
40
76
|
/**
|
|
41
|
-
* Track an event
|
|
77
|
+
* Track an event. Pass MCP request metadata to auto-extract session, user,
|
|
78
|
+
* and location info from the provider (OpenAI, Anthropic, etc.).
|
|
42
79
|
*/
|
|
43
80
|
track: (event: TrackEvent) => Promise<{
|
|
44
81
|
eventId: string;
|
|
45
82
|
}>;
|
|
46
|
-
/**
|
|
47
|
-
* Extract session ID from MCP request metadata, or generate a new one.
|
|
48
|
-
* If a new session ID is generated, automatically tracks a session.started event.
|
|
49
|
-
*
|
|
50
|
-
* @param meta - The _meta object from the MCP request (extra?._meta)
|
|
51
|
-
* @returns The session ID (existing or newly generated)
|
|
52
|
-
*/
|
|
53
|
-
getOrCreateSession: (meta?: Record<string, unknown>) => Promise<string>;
|
|
54
83
|
}
|
|
55
84
|
|
|
56
85
|
interface WaniWaniConfig {
|
|
@@ -101,4 +130,4 @@ interface WaniWaniClient extends TrackingClient {
|
|
|
101
130
|
*/
|
|
102
131
|
declare function waniwani(config?: WaniWaniConfig): WaniWaniClient;
|
|
103
132
|
|
|
104
|
-
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/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\
|
|
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"]}
|