Skip to content

Commit b5c91ca

Browse files
authored
🤖 Merge PR DefinitelyTyped#71918 feat(kochava): add type definitions for kochava SDK by @midoghranek
1 parent 6d54596 commit b5c91ca

File tree

5 files changed

+232
-0
lines changed

5 files changed

+232
-0
lines changed

‎types/kochava/.npmignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

‎types/kochava/index.d.ts‎

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/**
2+
* Kochava SDK instance
3+
*/
4+
export class Kochava {
5+
constructor();
6+
7+
/**
8+
* Creates a new Kochava SDK instance for the browser
9+
* @returns Kochava
10+
*/
11+
static create(): Kochava;
12+
/**
13+
* Creates a new Kochava SDK instance for the node
14+
* @returns Kochava
15+
*/
16+
static createForNode(): Kochava;
17+
/**
18+
* Creates a new Kochava SDK instance for React
19+
* @returns Kochava
20+
*/
21+
static createForReact(): Kochava;
22+
/**
23+
* Creates a new Kochava SDK instance for Vue
24+
* @returns Kochava
25+
*/
26+
static createForVue(): Kochava;
27+
/**
28+
* Creates a new Kochava SDK instance for Angular
29+
* @returns Kochava
30+
*/
31+
static createForAngular(): Kochava;
32+
33+
/**
34+
* Start the Kochava SDK with the app GUID
35+
* @param guid - the app GUID
36+
* @returns void
37+
*/
38+
startWithAppGuid(appGuid: string): void;
39+
40+
/**
41+
* sendPageEvent - Send a page event to Kochava
42+
* @param pageName - the name of the page
43+
* @param data - the data to send
44+
* @returns void
45+
*/
46+
sendPageEvent(pageName: string, additionalData?: EventData): void;
47+
48+
/**
49+
* sendEvent - Send an event to Kochava
50+
* @param name - the name of the event
51+
* @param data - the data to send with the event (optional)
52+
*/
53+
sendEvent(name: string, data?: string | EventData): void;
54+
55+
/**
56+
* registerIdentityLink - Register an identity link with Kochava
57+
* @param name - the name of the identity link
58+
* @param identifier - the identifier for the identity link
59+
* @returns void
60+
*/
61+
registerIdentityLink(name: string, identifier: string): void;
62+
63+
/**
64+
* setSleep - Set the sleep state of the SDK
65+
* @param sleep - the sleep state
66+
* @returns void
67+
*/
68+
setSleep(sleep: boolean): void;
69+
70+
/**
71+
* getDeviceId - Get the device ID from Kochava
72+
* @returns string - the device ID
73+
*/
74+
getDeviceId(): string;
75+
76+
/**
77+
* setLogLevel - Set the log level for the SDK
78+
* @param logLevel - the log level
79+
* @returns void
80+
*/
81+
setLogLevel(logLevel: LogLevel): void;
82+
83+
/**
84+
* shutdown - Shutdown the SDK
85+
* @param deleteData - clear the SDK state
86+
* @returns void
87+
*/
88+
shutdown(deleteData: boolean): void;
89+
90+
/**
91+
* useCookies - Enable or disable cookies
92+
* @param condition - boolean to enable or disable
93+
*/
94+
useCookies(condition: boolean): void;
95+
96+
/**
97+
* disableAutoPage - Disable auto page tracking
98+
* @param condition - boolean to enable or disable
99+
*/
100+
disableAutoPage(condition: boolean): void;
101+
102+
/**
103+
* executeAdvancedInstruction - Execute an advanced instruction
104+
* @param key - the key of the instruction
105+
* @param valueStr - the JSON string of the instruction
106+
* @param callback - the callback to call with the instance
107+
*/
108+
executeAdvancedInstruction(
109+
key: string,
110+
valueStr: string,
111+
callback?: (result: string) => void,
112+
): void;
113+
114+
/**
115+
* registerCustomValue - Register a custom value with Kochava
116+
* @param name - the name of the custom value
117+
* @param value - the value of the custom value
118+
*/
119+
registerCustomValue(name: string, value: string): void;
120+
121+
/**
122+
* registerCustomDeviceIdentifier - Register a custom device identifier with Kochava
123+
* @param name - the name of the custom device identifier
124+
* @param value - the value of the custom device identifier
125+
*/
126+
registerCustomDeviceIdentifier(name: string, value: string): void;
127+
128+
/**
129+
* getStarted - Get the started state of the SDK
130+
* @returns boolean - the started state
131+
*/
132+
getStarted(): boolean;
133+
}
134+
135+
// add koachava to window and global scope
136+
declare global {
137+
// access using window.kochava
138+
interface Window {
139+
/**
140+
* Kochava instance
141+
* it could be undefined if the SDK is not loaded
142+
* make sure to check if it's defined before using it
143+
* @example window.kochava.startWithAppGuid("app-guid");
144+
* @example window.kochava.sendPageEvent("page-name", { data: "data" });
145+
*/
146+
readonly kochava?: Kochava;
147+
}
148+
/**
149+
* Kochava instance,
150+
* it could be undefined if the SDK is not loaded,
151+
* make sure to check if it's defined before using it
152+
* @example kochava.startWithAppGuid("app-guid");
153+
* @example kochava.sendPageEvent("page-name", { data: "data" });
154+
*/
155+
const kochava: Kochava | undefined;
156+
}
157+
158+
// internal types
159+
export type LogLevel = "none" | "error" | "warn" | "info" | "debug" | "trace";
160+
export interface EventData {
161+
readonly [key: string]: string | number | boolean | null;
162+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Kochava } from "kochava";
2+
3+
const kochava = Kochava.create(); // $ExpectType Kochava
4+
Kochava.createForNode(); // $ExpectType Kochava
5+
Kochava.createForReact(); // $ExpectType Kochava
6+
Kochava.createForVue(); // $ExpectType Kochava
7+
Kochava.createForAngular(); // $ExpectType Kochava
8+
9+
kochava.startWithAppGuid("app-guid"); // $ExpectType void
10+
kochava.sendPageEvent("page-name", { data: "data" }); // $ExpectType void
11+
kochava.sendEvent("event-name", { data: "data" }); // $ExpectType void
12+
kochava.registerIdentityLink("identity-link-name", "identifier"); // $ExpectType void
13+
kochava.setSleep(true); // $ExpectType void
14+
kochava.getDeviceId(); // $ExpectType string
15+
kochava.setLogLevel("info"); // $ExpectType void
16+
kochava.shutdown(true); // $ExpectType void
17+
kochava.shutdown(false); // $ExpectType void
18+
kochava.useCookies(true); // $ExpectType void
19+
kochava.useCookies(false); // $ExpectType void
20+
kochava.disableAutoPage(true); // $ExpectType void
21+
kochava.disableAutoPage(false); // $ExpectType void
22+
kochava.executeAdvancedInstruction("wrapper", "{data:\"some data\"}", () => {}); // $ExpectType void
23+
kochava.registerCustomValue("key", "value"); // $ExpectType void
24+
kochava.registerCustomDeviceIdentifier("key", "value"); // $ExpectType void
25+
kochava.getStarted(); // $ExpectType boolean

‎types/kochava/package.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"private": true,
3+
"name": "@types/kochava",
4+
"version": "3.1.9999",
5+
"projects": [
6+
"https://www.npmjs.com/package/kochava"
7+
],
8+
"devDependencies": {
9+
"@types/kochava": "workspace:."
10+
},
11+
"owners": [
12+
{
13+
"name": "Muhammad Abu 'l-Gharaniq",
14+
"githubUsername": "midoghranek"
15+
},
16+
{
17+
"name": "Armia Talaat",
18+
"githubUsername": "armia-talaat"
19+
}
20+
]
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"kochava-tests.ts"
18+
]
19+
}

0 commit comments

Comments
 (0)