@klime/node 1.0.3 → 1.2.1
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/README.md +233 -25
- package/dist/index.cjs +545 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +110 -0
- package/dist/index.d.ts +86 -4
- package/dist/index.js +483 -393
- package/dist/index.js.map +1 -0
- package/package.json +18 -3
- package/dist/types.d.ts +0 -54
- package/dist/types.js +0 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
interface Logger {
|
|
2
|
+
debug(message: string, ...args: any[]): void;
|
|
3
|
+
info(message: string, ...args: any[]): void;
|
|
4
|
+
warn(message: string, ...args: any[]): void;
|
|
5
|
+
error(message: string, ...args: any[]): void;
|
|
6
|
+
}
|
|
7
|
+
interface KlimeConfig {
|
|
8
|
+
writeKey: string;
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
flushInterval?: number;
|
|
11
|
+
maxBatchSize?: number;
|
|
12
|
+
maxQueueSize?: number;
|
|
13
|
+
retryMaxAttempts?: number;
|
|
14
|
+
retryInitialDelay?: number;
|
|
15
|
+
flushOnShutdown?: boolean;
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
onError?: (error: Error, events: Event[]) => void;
|
|
18
|
+
onSuccess?: (response: BatchResponse) => void;
|
|
19
|
+
}
|
|
20
|
+
interface TrackOptions {
|
|
21
|
+
userId?: string;
|
|
22
|
+
groupId?: string;
|
|
23
|
+
}
|
|
24
|
+
interface IdentifyOptions {
|
|
25
|
+
}
|
|
26
|
+
interface GroupOptions {
|
|
27
|
+
userId?: string;
|
|
28
|
+
}
|
|
29
|
+
interface Event {
|
|
30
|
+
type: 'track' | 'identify' | 'group';
|
|
31
|
+
messageId: string;
|
|
32
|
+
event?: string;
|
|
33
|
+
userId?: string;
|
|
34
|
+
groupId?: string;
|
|
35
|
+
timestamp: string;
|
|
36
|
+
properties?: Record<string, any>;
|
|
37
|
+
traits?: Record<string, any>;
|
|
38
|
+
context?: EventContext;
|
|
39
|
+
}
|
|
40
|
+
interface EventContext {
|
|
41
|
+
library?: {
|
|
42
|
+
name: string;
|
|
43
|
+
version: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
interface BatchResponse {
|
|
47
|
+
status: string;
|
|
48
|
+
accepted: number;
|
|
49
|
+
failed: number;
|
|
50
|
+
errors?: ValidationError[];
|
|
51
|
+
}
|
|
52
|
+
interface ValidationError {
|
|
53
|
+
index: number;
|
|
54
|
+
message: string;
|
|
55
|
+
code: string;
|
|
56
|
+
}
|
|
57
|
+
declare class SendError extends Error {
|
|
58
|
+
events: Event[];
|
|
59
|
+
constructor(message: string, events: Event[]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare class KlimeClient {
|
|
63
|
+
private config;
|
|
64
|
+
private queue;
|
|
65
|
+
private flushTimer;
|
|
66
|
+
private isShutdown;
|
|
67
|
+
private flushPromise;
|
|
68
|
+
private shutdownHandlers;
|
|
69
|
+
constructor(config: KlimeConfig);
|
|
70
|
+
track(event: string, properties?: Record<string, any>, options?: TrackOptions): void;
|
|
71
|
+
identify(userId: string, traits?: Record<string, any>, options?: IdentifyOptions): void;
|
|
72
|
+
group(groupId: string, traits?: Record<string, any>, options?: GroupOptions): void;
|
|
73
|
+
/**
|
|
74
|
+
* Track an event synchronously. Returns BatchResponse or throws SendError.
|
|
75
|
+
*/
|
|
76
|
+
trackSync(event: string, properties?: Record<string, any>, options?: TrackOptions): Promise<BatchResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Identify a user synchronously. Returns BatchResponse or throws SendError.
|
|
79
|
+
*/
|
|
80
|
+
identifySync(userId: string, traits?: Record<string, any>, options?: IdentifyOptions): Promise<BatchResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Associate a user with a group synchronously. Returns BatchResponse or throws SendError.
|
|
83
|
+
*/
|
|
84
|
+
groupSync(groupId: string, traits?: Record<string, any>, options?: GroupOptions): Promise<BatchResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Return the number of events currently in the queue.
|
|
87
|
+
*/
|
|
88
|
+
getQueueSize(): number;
|
|
89
|
+
flush(): Promise<void>;
|
|
90
|
+
shutdown(): Promise<void>;
|
|
91
|
+
private enqueue;
|
|
92
|
+
private doFlush;
|
|
93
|
+
private extractBatch;
|
|
94
|
+
private sendBatch;
|
|
95
|
+
private sendSync;
|
|
96
|
+
private doSend;
|
|
97
|
+
private doSendWithFetch;
|
|
98
|
+
private doSendWithHttps;
|
|
99
|
+
private invokeOnError;
|
|
100
|
+
private invokeOnSuccess;
|
|
101
|
+
private makeRequest;
|
|
102
|
+
private scheduleFlush;
|
|
103
|
+
private generateUUID;
|
|
104
|
+
private generateTimestamp;
|
|
105
|
+
private getContext;
|
|
106
|
+
private estimateEventSize;
|
|
107
|
+
private sleep;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { type BatchResponse, type Event, type GroupOptions, type IdentifyOptions, KlimeClient, type KlimeConfig, type Logger, SendError, type TrackOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface Logger {
|
|
2
|
+
debug(message: string, ...args: any[]): void;
|
|
3
|
+
info(message: string, ...args: any[]): void;
|
|
4
|
+
warn(message: string, ...args: any[]): void;
|
|
5
|
+
error(message: string, ...args: any[]): void;
|
|
6
|
+
}
|
|
7
|
+
interface KlimeConfig {
|
|
8
|
+
writeKey: string;
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
flushInterval?: number;
|
|
11
|
+
maxBatchSize?: number;
|
|
12
|
+
maxQueueSize?: number;
|
|
13
|
+
retryMaxAttempts?: number;
|
|
14
|
+
retryInitialDelay?: number;
|
|
15
|
+
flushOnShutdown?: boolean;
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
onError?: (error: Error, events: Event[]) => void;
|
|
18
|
+
onSuccess?: (response: BatchResponse) => void;
|
|
19
|
+
}
|
|
20
|
+
interface TrackOptions {
|
|
21
|
+
userId?: string;
|
|
22
|
+
groupId?: string;
|
|
23
|
+
}
|
|
24
|
+
interface IdentifyOptions {
|
|
25
|
+
}
|
|
26
|
+
interface GroupOptions {
|
|
27
|
+
userId?: string;
|
|
28
|
+
}
|
|
29
|
+
interface Event {
|
|
30
|
+
type: 'track' | 'identify' | 'group';
|
|
31
|
+
messageId: string;
|
|
32
|
+
event?: string;
|
|
33
|
+
userId?: string;
|
|
34
|
+
groupId?: string;
|
|
35
|
+
timestamp: string;
|
|
36
|
+
properties?: Record<string, any>;
|
|
37
|
+
traits?: Record<string, any>;
|
|
38
|
+
context?: EventContext;
|
|
39
|
+
}
|
|
40
|
+
interface EventContext {
|
|
41
|
+
library?: {
|
|
42
|
+
name: string;
|
|
43
|
+
version: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
interface BatchResponse {
|
|
47
|
+
status: string;
|
|
48
|
+
accepted: number;
|
|
49
|
+
failed: number;
|
|
50
|
+
errors?: ValidationError[];
|
|
51
|
+
}
|
|
52
|
+
interface ValidationError {
|
|
53
|
+
index: number;
|
|
54
|
+
message: string;
|
|
55
|
+
code: string;
|
|
56
|
+
}
|
|
57
|
+
declare class SendError extends Error {
|
|
58
|
+
events: Event[];
|
|
59
|
+
constructor(message: string, events: Event[]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare class KlimeClient {
|
|
3
63
|
private config;
|
|
4
64
|
private queue;
|
|
5
65
|
private flushTimer;
|
|
@@ -10,14 +70,34 @@ export declare class KlimeClient {
|
|
|
10
70
|
track(event: string, properties?: Record<string, any>, options?: TrackOptions): void;
|
|
11
71
|
identify(userId: string, traits?: Record<string, any>, options?: IdentifyOptions): void;
|
|
12
72
|
group(groupId: string, traits?: Record<string, any>, options?: GroupOptions): void;
|
|
73
|
+
/**
|
|
74
|
+
* Track an event synchronously. Returns BatchResponse or throws SendError.
|
|
75
|
+
*/
|
|
76
|
+
trackSync(event: string, properties?: Record<string, any>, options?: TrackOptions): Promise<BatchResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Identify a user synchronously. Returns BatchResponse or throws SendError.
|
|
79
|
+
*/
|
|
80
|
+
identifySync(userId: string, traits?: Record<string, any>, options?: IdentifyOptions): Promise<BatchResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Associate a user with a group synchronously. Returns BatchResponse or throws SendError.
|
|
83
|
+
*/
|
|
84
|
+
groupSync(groupId: string, traits?: Record<string, any>, options?: GroupOptions): Promise<BatchResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Return the number of events currently in the queue.
|
|
87
|
+
*/
|
|
88
|
+
getQueueSize(): number;
|
|
13
89
|
flush(): Promise<void>;
|
|
14
90
|
shutdown(): Promise<void>;
|
|
15
91
|
private enqueue;
|
|
16
92
|
private doFlush;
|
|
17
93
|
private extractBatch;
|
|
18
94
|
private sendBatch;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
95
|
+
private sendSync;
|
|
96
|
+
private doSend;
|
|
97
|
+
private doSendWithFetch;
|
|
98
|
+
private doSendWithHttps;
|
|
99
|
+
private invokeOnError;
|
|
100
|
+
private invokeOnSuccess;
|
|
21
101
|
private makeRequest;
|
|
22
102
|
private scheduleFlush;
|
|
23
103
|
private generateUUID;
|
|
@@ -26,3 +106,5 @@ export declare class KlimeClient {
|
|
|
26
106
|
private estimateEventSize;
|
|
27
107
|
private sleep;
|
|
28
108
|
}
|
|
109
|
+
|
|
110
|
+
export { type BatchResponse, type Event, type GroupOptions, type IdentifyOptions, KlimeClient, type KlimeConfig, type Logger, SendError, type TrackOptions };
|