@jitsu/protocols 0.0.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 ADDED
@@ -0,0 +1,201 @@
1
+ import { ISO8601Date } from "./iso8601.d";
2
+
3
+ export type ID = string | null | undefined;
4
+
5
+ export type DataLayoutType = "segment" | "jitsu-legacy" | "segment-single-table";
6
+
7
+ /**
8
+ * Event coming from client library
9
+ */
10
+ export interface AnalyticsClientEvent {
11
+ /**
12
+ * Unique message ID
13
+ */
14
+ messageId: string;
15
+ timestamp?: Date | ISO8601Date;
16
+ type: "track" | "page" | "identify" | "group" | "alias" | "screen";
17
+ // page specific
18
+ category?: string;
19
+ name?: string;
20
+
21
+ properties?: {
22
+ [k: string]: JSONValue;
23
+ };
24
+ /**
25
+ * Traits can be either here, or in context.traits (depending on a library)
26
+ */
27
+ traits?: JSONObject;
28
+
29
+ context: AnalyticsContext;
30
+
31
+ userId?: ID;
32
+ anonymousId?: ID;
33
+ groupId?: ID;
34
+ previousId?: ID;
35
+
36
+ event?: string;
37
+ writeKey?: string;
38
+ sentAt?: Date | ISO8601Date;
39
+ }
40
+
41
+ export type ServerContextReservedProps = {
42
+ request_ip?: string;
43
+ receivedAt?: ISO8601Date;
44
+ sentAt?: ISO8601Date;
45
+ timestamp?: ISO8601Date;
46
+ userId?: ISO8601Date;
47
+ type?: ISO8601Date;
48
+ };
49
+ /**
50
+ * A context of an event that is added on server-side
51
+ */
52
+ export type ServerContext = ServerContextReservedProps & { [k: string]: any };
53
+
54
+ interface ProcessingContext {
55
+ $table?: string;
56
+ [k: `$${string}`]: any;
57
+ }
58
+
59
+ export type AnalyticsServerEvent = AnalyticsClientEvent & ServerContext & ProcessingContext;
60
+
61
+ export type JSONPrimitive = string | number | boolean | null;
62
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
63
+ export type JSONObject = { [member: string]: JSONValue };
64
+ export type JSONArray = Array<JSONValue>;
65
+
66
+ export type Integrations = {
67
+ All?: boolean;
68
+ [integration: string]: boolean | JSONObject | undefined;
69
+ };
70
+
71
+ export type Options = {
72
+ integrations?: Integrations;
73
+ anonymousId?: ID;
74
+ timestamp?: Date | string;
75
+ context?: AnalyticsContext;
76
+ traits?: JSONObject;
77
+
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
+ [key: string]: any;
80
+ };
81
+
82
+ type CompactMetricType = "g" | "c";
83
+
84
+ export interface CompactMetric {
85
+ m: string; // metric name
86
+ v: number; // value
87
+ k: CompactMetricType;
88
+ t: string[]; // tags
89
+ e: number; // timestamp in unit milliseconds
90
+ }
91
+
92
+ export type PageReservedProps = {
93
+ path?: string;
94
+ referrer?: string;
95
+ host?: string;
96
+ referring_domain?: string;
97
+ search?: string;
98
+ title?: string;
99
+ url?: string;
100
+ };
101
+
102
+ interface AnalyticsContext {
103
+ /**
104
+ * Ip address of the originating request. Generally, shouldn't be set
105
+ * for client-side track calls.
106
+ */
107
+ ip?: string;
108
+
109
+ page?: PageReservedProps & { [key: string]: any };
110
+ metrics?: CompactMetric[];
111
+
112
+ userAgent?: string;
113
+
114
+ userAgentVendor?: string;
115
+
116
+ locale?: string;
117
+
118
+ library?: {
119
+ name: string;
120
+ version: string;
121
+ };
122
+
123
+ traits?: { crossDomainId?: string } & JSONObject;
124
+
125
+ campaign?: {
126
+ name?: string;
127
+ term?: string;
128
+ source?: string;
129
+ medium?: string;
130
+ content?: string;
131
+ [key: string]: any;
132
+ };
133
+
134
+ referrer?: {
135
+ btid?: string;
136
+ urid?: string;
137
+ };
138
+
139
+ amp?: {
140
+ id: string;
141
+ };
142
+
143
+ [key: string]: any;
144
+ }
145
+
146
+ export type Context = any;
147
+ export type DispatchedEvent = Context;
148
+
149
+ export type Callback = (ctx: Context | undefined) => Promise<unknown> | unknown;
150
+
151
+ export interface AnalyticsInterface {
152
+ track(
153
+ eventName: string | JSONObject,
154
+ properties?: JSONObject | Callback,
155
+ options?: Options | Callback,
156
+ callback?: Callback
157
+ ): Promise<DispatchedEvent>;
158
+
159
+ page(
160
+ category?: string | object,
161
+ name?: string | object | Callback,
162
+ properties?: object | Options | Callback | null,
163
+ options?: Options | Callback,
164
+ callback?: Callback
165
+ ): Promise<DispatchedEvent>;
166
+ //Original Segment Identify, not supported yet, see a subset below
167
+ // identify(
168
+ // id?: ID | object,
169
+ // traits?: JSONObject | Callback | null,
170
+ // options?: Options | Callback,
171
+ // callback?: Callback,
172
+ // ): Promise<DispatchedEvent>;
173
+
174
+ identify(id?: ID | object, traits?: JSONObject | Callback | null, callback?: Callback): Promise<DispatchedEvent>;
175
+
176
+ reset(callback?: (...params: any[]) => any): Promise<any>;
177
+
178
+ user(): any;
179
+
180
+ //TODO: user,reset
181
+
182
+ // alias(
183
+ // to: string | number,
184
+ // from?: string | number | Options,
185
+ // options?: Options | Callback,
186
+ // callback?: Callback
187
+ // ): Promise<DispatchedEvent>;
188
+ // group(
189
+ // id?: ID | object,
190
+ // traits?: JSONObject | Callback | null,
191
+ // options?: Options | Callback,
192
+ // callback?: Callback
193
+ // ): Promise<DispatchedEvent>;
194
+ // screen(
195
+ // category?: string | object,
196
+ // name?: string | object | Callback,
197
+ // properties?: JSONObject | Options | Callback | null,
198
+ // options?: Options | Callback,
199
+ // callback?: Callback
200
+ // ): Promise<DispatchedEvent>;
201
+ }
@@ -0,0 +1,16 @@
1
+ import { ISO8601Date } from "./iso8601";
2
+
3
+ export type IngestMessage = {
4
+ messageCreated: ISO8601Date;
5
+ writeKey: string;
6
+ messageId: string;
7
+ connectionId: string;
8
+ type: string;
9
+ origin: {
10
+ baseUrl: string;
11
+ slug?: string;
12
+ domain?: string;
13
+ };
14
+ httpHeaders: Record<string, string>;
15
+ httpPayload: any;
16
+ };
package/functions.d.ts ADDED
@@ -0,0 +1,93 @@
1
+ export type SetOpts = { ttlMs?: number } | { ttlSec?: number };
2
+
3
+ /**
4
+ * A key value store that exposed to a function
5
+ */
6
+ export type Store = {
7
+ get(key: string): Promise<any>;
8
+ del(key: string): Promise<void>;
9
+ set(key: string, value: any, opts?: SetOpts): Promise<void>;
10
+ };
11
+
12
+ /**
13
+ * A special properties that user can set on an event to define how
14
+ * event will be processed further
15
+ */
16
+ export type EventControlOpts = {
17
+ /**
18
+ * Table name to store event in. Non-SQL destinations might ignore this property
19
+ */
20
+ JITSU_TABLE_NAME?: string;
21
+ };
22
+
23
+ export type AnyEvent = Record<string, any> & EventControlOpts;
24
+ export type AnyProps = Record<string, any>;
25
+
26
+ export type FetchResponse = {
27
+ status: number;
28
+ statusText: string;
29
+ text: () => Promise<string>;
30
+ json: () => Promise<any>;
31
+ };
32
+
33
+ export type FetchOpts = {
34
+ method?: string;
35
+ headers?: Record<string, string>;
36
+ body?: string;
37
+ };
38
+ export type GlobalContext = {
39
+ log: {
40
+ info: (message: string, ...args: any[]) => void;
41
+ debug: (message: string, ...args: any[]) => void;
42
+ error: (message: string, ...args: any[]) => void;
43
+ };
44
+ fetch: (url: string, opts?: FetchOpts) => Promise<FetchResponse>;
45
+ store: Store;
46
+ };
47
+
48
+ export type EventContext = {
49
+ /**
50
+ * Headers of incoming request
51
+ */
52
+ headers: Record<string, string>;
53
+ /**
54
+ * Source of the incoming event
55
+ */
56
+ source?: {
57
+ id: string;
58
+ name?: string;
59
+ domain?: string;
60
+ };
61
+ destination?: {
62
+ id: string;
63
+ type: string;
64
+ };
65
+ };
66
+
67
+ export type FunctionConfigContext<P extends AnyProps = AnyProps> = {
68
+ props: P;
69
+ };
70
+
71
+ /**
72
+ * Parameters for a function
73
+ */
74
+ export type FunctionContext<P extends AnyProps = AnyProps> = EventContext & GlobalContext & FunctionConfigContext<P>;
75
+
76
+ //equivalent to returning [] from a function
77
+ export type FunctionCommand = "interrupt";
78
+
79
+ export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand;
80
+
81
+ export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps = AnyProps> {
82
+ (event: E, ctx: FunctionContext<P>): Promise<FuncReturn> | FuncReturn;
83
+
84
+ displayName?: string;
85
+ //for future use - config schema of the function
86
+ configSchema?: any;
87
+
88
+ //It's allowed to use basic JSX
89
+ description?: any;
90
+ }
91
+
92
+ export type BuiltinFunctionName<T extends string = string> = `builtin.${T}`;
93
+ export type BuiltinDestinationFunctionName = BuiltinFunctionName<`destination.${string}`>;
package/iso8601.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ //TODO: add an actual type for ISO 8601 date
2
+ export type ISO8601Date = string;
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@jitsu/protocols",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "author": "Jitsu Dev Team <dev@jitsu.com>",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "license": "MIT",
10
+ "private": false,
11
+ "devDependencies": {},
12
+ "dependencies": {},
13
+ "scripts": {}
14
+ }