@jitsu/protocols 1.1.0-canary.212.20230220173912 → 1.2.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/analytics.d.ts +18 -17
- package/async-request.d.ts +3 -0
- package/functions.d.ts +44 -7
- package/package.json +1 -2
package/analytics.d.ts
CHANGED
|
@@ -39,6 +39,10 @@ export interface AnalyticsClientEvent {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export type ServerContextReservedProps = {
|
|
42
|
+
//always filled with an IP from where request came from
|
|
43
|
+
//if request came server-to-server, then it's an IP of a server
|
|
44
|
+
//for device events it will be an IP of a device
|
|
45
|
+
//don't use this field in functions, use context.ip instead
|
|
42
46
|
request_ip?: string;
|
|
43
47
|
receivedAt?: ISO8601Date;
|
|
44
48
|
sentAt?: ISO8601Date;
|
|
@@ -53,6 +57,7 @@ export type ServerContext = ServerContextReservedProps & { [k: string]: any };
|
|
|
53
57
|
|
|
54
58
|
interface ProcessingContext {
|
|
55
59
|
$table?: string;
|
|
60
|
+
|
|
56
61
|
[k: `$${string}`]: any;
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -70,6 +75,7 @@ export type Integrations = {
|
|
|
70
75
|
|
|
71
76
|
export type Options = {
|
|
72
77
|
integrations?: Integrations;
|
|
78
|
+
userId?: ID;
|
|
73
79
|
anonymousId?: ID;
|
|
74
80
|
timestamp?: Date | string;
|
|
75
81
|
context?: AnalyticsContext;
|
|
@@ -101,8 +107,10 @@ export type PageReservedProps = {
|
|
|
101
107
|
|
|
102
108
|
interface AnalyticsContext {
|
|
103
109
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
110
|
+
* IP address of the originating request. If event is sent from a device, then it's an IP of a device
|
|
111
|
+
* (copied from request_ip)
|
|
112
|
+
* If request is sent from server-to-server, this field is not automatically populated
|
|
113
|
+
* and should be filled manually
|
|
106
114
|
*/
|
|
107
115
|
ip?: string;
|
|
108
116
|
|
|
@@ -163,13 +171,13 @@ export interface AnalyticsInterface {
|
|
|
163
171
|
options?: Options | Callback,
|
|
164
172
|
callback?: Callback
|
|
165
173
|
): Promise<DispatchedEvent>;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
|
|
175
|
+
group(
|
|
176
|
+
groupId?: ID | object,
|
|
177
|
+
traits?: JSONObject | null,
|
|
178
|
+
options?: Options,
|
|
179
|
+
callback?: Callback
|
|
180
|
+
): Promise<DispatchedEvent>;
|
|
173
181
|
|
|
174
182
|
identify(id?: ID | object, traits?: JSONObject | Callback | null, callback?: Callback): Promise<DispatchedEvent>;
|
|
175
183
|
|
|
@@ -177,20 +185,13 @@ export interface AnalyticsInterface {
|
|
|
177
185
|
|
|
178
186
|
user(): any;
|
|
179
187
|
|
|
180
|
-
//TODO: user,reset
|
|
181
|
-
|
|
182
188
|
// alias(
|
|
183
189
|
// to: string | number,
|
|
184
190
|
// from?: string | number | Options,
|
|
185
191
|
// options?: Options | Callback,
|
|
186
192
|
// callback?: Callback
|
|
187
193
|
// ): Promise<DispatchedEvent>;
|
|
188
|
-
|
|
189
|
-
// id?: ID | object,
|
|
190
|
-
// traits?: JSONObject | Callback | null,
|
|
191
|
-
// options?: Options | Callback,
|
|
192
|
-
// callback?: Callback
|
|
193
|
-
// ): Promise<DispatchedEvent>;
|
|
194
|
+
|
|
194
195
|
// screen(
|
|
195
196
|
// category?: string | object,
|
|
196
197
|
// name?: string | object | Callback,
|
package/async-request.d.ts
CHANGED
package/functions.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import { AnalyticsServerEvent } from "./analytics";
|
|
2
|
+
import { RequestOptions } from "http";
|
|
3
|
+
|
|
1
4
|
export type SetOpts = { ttlMs?: number } | { ttlSec?: number };
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* A key value store that exposed to a function
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
interface Store {
|
|
7
10
|
get(key: string): Promise<any>;
|
|
8
11
|
del(key: string): Promise<void>;
|
|
9
12
|
set(key: string, value: any, opts?: SetOpts): Promise<void>;
|
|
10
|
-
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Store for incoming events, destination results and function log messages
|
|
17
|
+
*/
|
|
18
|
+
interface EventsStore {
|
|
19
|
+
log(error: boolean, msg: Record<string, any>): Promise<void>;
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
/**
|
|
13
23
|
* A special properties that user can set on an event to define how
|
|
@@ -33,18 +43,34 @@ export type FetchResponse = {
|
|
|
33
43
|
export type FetchOpts = {
|
|
34
44
|
method?: string;
|
|
35
45
|
headers?: Record<string, string>;
|
|
46
|
+
agent?: RequestOptions["agent"] | ((parsedUrl: URL) => RequestOptions["agent"]);
|
|
36
47
|
body?: string;
|
|
37
48
|
};
|
|
38
|
-
export type
|
|
49
|
+
export type FunctionContext = {
|
|
39
50
|
log: {
|
|
40
51
|
info: (message: string, ...args: any[]) => void;
|
|
52
|
+
warn: (message: string, ...args: any[]) => void;
|
|
41
53
|
debug: (message: string, ...args: any[]) => void;
|
|
42
54
|
error: (message: string, ...args: any[]) => void;
|
|
43
55
|
};
|
|
44
|
-
fetch: (url: string, opts?: FetchOpts) => Promise<FetchResponse>;
|
|
56
|
+
fetch: (url: string, opts?: FetchOpts, logToRedis?: boolean) => Promise<FetchResponse>;
|
|
45
57
|
store: Store;
|
|
46
58
|
};
|
|
47
59
|
|
|
60
|
+
export type AnonymousEventsStore = {
|
|
61
|
+
addEvent(collectionName: string, anonymousId: string, event: AnalyticsServerEvent, ttlDays: number): Promise<void>;
|
|
62
|
+
evictEvents(collectionName: string, anonymousId: string): Promise<AnalyticsServerEvent[]>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Function execution context available for builin functions only
|
|
67
|
+
*/
|
|
68
|
+
export type SystemContext = {
|
|
69
|
+
$system: {
|
|
70
|
+
anonymousEventsStore: AnonymousEventsStore;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
48
74
|
export type EventContext = {
|
|
49
75
|
/**
|
|
50
76
|
* Headers of incoming request
|
|
@@ -61,6 +87,13 @@ export type EventContext = {
|
|
|
61
87
|
destination?: {
|
|
62
88
|
id: string;
|
|
63
89
|
type: string;
|
|
90
|
+
updatedAt: Date;
|
|
91
|
+
hash: string;
|
|
92
|
+
};
|
|
93
|
+
connection?: {
|
|
94
|
+
id: string;
|
|
95
|
+
mode?: string;
|
|
96
|
+
options?: any;
|
|
64
97
|
};
|
|
65
98
|
};
|
|
66
99
|
|
|
@@ -71,15 +104,18 @@ export type FunctionConfigContext<P extends AnyProps = AnyProps> = {
|
|
|
71
104
|
/**
|
|
72
105
|
* Parameters for a function
|
|
73
106
|
*/
|
|
74
|
-
export type
|
|
107
|
+
export type FullContext<P extends AnyProps = AnyProps> = EventContext &
|
|
108
|
+
FunctionContext &
|
|
109
|
+
FunctionConfigContext<P> &
|
|
110
|
+
(SystemContext | {});
|
|
75
111
|
|
|
76
112
|
//equivalent to returning [] from a function
|
|
77
|
-
export type FunctionCommand = "
|
|
113
|
+
export type FunctionCommand = "drop";
|
|
78
114
|
|
|
79
115
|
export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand;
|
|
80
116
|
|
|
81
117
|
export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps = AnyProps> {
|
|
82
|
-
(event: E, ctx:
|
|
118
|
+
(event: E, ctx: FullContext<P>): Promise<FuncReturn> | FuncReturn;
|
|
83
119
|
|
|
84
120
|
displayName?: string;
|
|
85
121
|
//for future use - config schema of the function
|
|
@@ -91,3 +127,4 @@ export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps
|
|
|
91
127
|
|
|
92
128
|
export type BuiltinFunctionName<T extends string = string> = `builtin.${T}`;
|
|
93
129
|
export type BuiltinDestinationFunctionName = BuiltinFunctionName<`destination.${string}`>;
|
|
130
|
+
export type BuiltinTransformationFunctionName = BuiltinFunctionName<`transformation.${string}`>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/protocols",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Jitsu Dev Team <dev@jitsu.com>",
|
|
6
6
|
"publishConfig": {
|
|
@@ -9,6 +9,5 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"private": false,
|
|
11
11
|
"devDependencies": {},
|
|
12
|
-
"dependencies": {},
|
|
13
12
|
"scripts": {}
|
|
14
13
|
}
|