@jitsu/protocols 1.1.0-canary.227.20230222142636 → 1.3.0-canary.231.20230920071611

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Jitsu Labs, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/analytics.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ISO8601Date } from "./iso8601.d";
2
2
 
3
3
  export type ID = string | null | undefined;
4
4
 
5
- export type DataLayoutType = "segment" | "jitsu-legacy" | "segment-single-table";
5
+ export type DataLayoutType = "segment" | "jitsu-legacy" | "segment-single-table" | "passthrough";
6
6
 
7
7
  /**
8
8
  * Event coming from client library
@@ -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
- * Ip address of the originating request. Generally, shouldn't be set
105
- * for client-side track calls.
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
- //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>;
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
- // group(
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,
@@ -1,6 +1,11 @@
1
1
  import { ISO8601Date } from "./iso8601";
2
+ import { Geo } from "./functions";
3
+
4
+ export type IngestType = "s2s" | "browser";
2
5
 
3
6
  export type IngestMessage = {
7
+ geo?: Geo;
8
+ ingestType: IngestType;
4
9
  messageCreated: ISO8601Date;
5
10
  writeKey: string;
6
11
  messageId: string;
package/functions.d.ts CHANGED
@@ -1,14 +1,22 @@
1
+ import { AnalyticsServerEvent } from "./analytics";
2
+
1
3
  export type SetOpts = { ttlMs?: number } | { ttlSec?: number };
2
4
 
3
5
  /**
4
6
  * A key value store that exposed to a function
5
7
  */
6
- export type Store = {
8
+ interface Store {
7
9
  get(key: string): Promise<any>;
8
10
  del(key: string): Promise<void>;
9
11
  set(key: string, value: any, opts?: SetOpts): Promise<void>;
10
- };
12
+ }
11
13
 
14
+ /**
15
+ * Store for incoming events, destination results and function log messages
16
+ */
17
+ interface EventsStore {
18
+ log(connectionId: string, error: boolean, msg: Record<string, any>): void;
19
+ }
12
20
  /**
13
21
  * A special properties that user can set on an event to define how
14
22
  * event will be processed further
@@ -35,17 +43,125 @@ export type FetchOpts = {
35
43
  headers?: Record<string, string>;
36
44
  body?: string;
37
45
  };
38
- export type GlobalContext = {
46
+ export type FunctionContext = {
39
47
  log: {
40
48
  info: (message: string, ...args: any[]) => void;
49
+ warn: (message: string, ...args: any[]) => void;
41
50
  debug: (message: string, ...args: any[]) => void;
42
51
  error: (message: string, ...args: any[]) => void;
43
52
  };
44
- fetch: (url: string, opts?: FetchOpts) => Promise<FetchResponse>;
53
+ fetch: (url: string, opts?: FetchOpts, logToRedis?: boolean) => Promise<FetchResponse>;
45
54
  store: Store;
46
55
  };
47
56
 
57
+ export type PrivacyOpts = {
58
+ /**
59
+ * IP address processing mode
60
+ * "keep" means that the IP address will be kept as is
61
+ * "reduce" means that the IP address will be reduced to the first 3 octets
62
+ * "hash" means that the IP address will be hashed with SHA256 (not implemented yet)
63
+ *
64
+ * "reduce" is the default behavior
65
+ */
66
+ ip?: "reduce" | "keep" | "hash";
67
+ /**
68
+ * Replaces cookie based anonymous ID with a fingerprint hash
69
+ * "hash1" means that anyonymous ID will be replaced with hash(ip + user_agent)
70
+ */
71
+ anonymousId?: "hash1" | "keep" | ((opts: { ip: string; ip3octets: string; userAgent: string }) => string);
72
+ };
73
+
74
+ export type CoreLib = {
75
+ privacy(event: AnalyticsServerEvent, opts?: PrivacyOpts): AnalyticsServerEvent;
76
+ };
77
+
78
+ export type AnonymousEventsStore = {
79
+ addEvent(collectionName: string, anonymousId: string, event: AnalyticsServerEvent, ttlDays: number): Promise<void>;
80
+ evictEvents(collectionName: string, anonymousId: string): Promise<AnalyticsServerEvent[]>;
81
+ };
82
+
83
+ /**
84
+ * Function execution context available for builin functions only
85
+ */
86
+ export type SystemContext = {
87
+ $system: {
88
+ anonymousEventsStore: AnonymousEventsStore;
89
+ };
90
+ };
91
+
92
+ export type WithConfidence<T> = T & {
93
+ //A value from 0-100 indicating how confident we are in the result
94
+ confidence?: number;
95
+ };
96
+
97
+ export type Geo = {
98
+ /**
99
+ * IP address of the incoming request
100
+ */
101
+ continent?: {
102
+ code: "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
103
+ };
104
+ country?: {
105
+ /**
106
+ * Two-letter country code (ISO 3166-1 alpha-2): https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
107
+ */
108
+ code: string;
109
+ isEU: boolean;
110
+ };
111
+ region?: WithConfidence<{
112
+ /**
113
+ * Code of the region (ISO 3166-2): https://en.wikipedia.org/wiki/ISO_3166-2.
114
+ * For USA it's two-letter capitaluzed state code (such as NY)
115
+ */
116
+ code: string;
117
+ }>;
118
+ city?: WithConfidence<{
119
+ name: string;
120
+ }>;
121
+
122
+ postalCode?: WithConfidence<{
123
+ code: string;
124
+ }>;
125
+
126
+ location?: {
127
+ latitude: number;
128
+ longitude: number;
129
+ accuracyRadius?: number;
130
+ /**
131
+ * Only for USA locations
132
+ */
133
+ usaData?: {
134
+ populationDensity?: number;
135
+ metroCode?: number;
136
+ averageIncome?: number;
137
+ };
138
+ };
139
+ provider?: {
140
+ /**
141
+ * Autonomous system number
142
+ */
143
+ as?: {
144
+ num: number;
145
+ name?: string;
146
+ };
147
+ connectionType?: string;
148
+ domain: string;
149
+ isAnonymousVpn?: boolean;
150
+ isHostingProvider?: boolean;
151
+ isLegitimateProxy?: boolean;
152
+ isPublicProxy?: boolean;
153
+ isResidentialProxy?: boolean;
154
+ isTorExitNode?: boolean;
155
+ userType?: string;
156
+ isp?: string;
157
+ };
158
+ };
159
+
48
160
  export type EventContext = {
161
+ /**
162
+ * Geo data of incoming request
163
+ */
164
+ geo?: Geo;
49
165
  /**
50
166
  * Headers of incoming request
51
167
  */
@@ -61,6 +177,13 @@ export type EventContext = {
61
177
  destination?: {
62
178
  id: string;
63
179
  type: string;
180
+ updatedAt: Date;
181
+ hash: string;
182
+ };
183
+ connection?: {
184
+ id: string;
185
+ mode?: string;
186
+ options?: any;
64
187
  };
65
188
  };
66
189
 
@@ -71,15 +194,18 @@ export type FunctionConfigContext<P extends AnyProps = AnyProps> = {
71
194
  /**
72
195
  * Parameters for a function
73
196
  */
74
- export type FunctionContext<P extends AnyProps = AnyProps> = EventContext & GlobalContext & FunctionConfigContext<P>;
197
+ export type FullContext<P extends AnyProps = AnyProps> = EventContext &
198
+ FunctionContext &
199
+ FunctionConfigContext<P> &
200
+ (SystemContext | {});
75
201
 
76
202
  //equivalent to returning [] from a function
77
- export type FunctionCommand = "interrupt";
203
+ export type FunctionCommand = "drop";
78
204
 
79
- export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand;
205
+ export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand | false;
80
206
 
81
207
  export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps = AnyProps> {
82
- (event: E, ctx: FunctionContext<P>): Promise<FuncReturn> | FuncReturn;
208
+ (event: E, ctx: FullContext<P>): Promise<FuncReturn> | FuncReturn;
83
209
 
84
210
  displayName?: string;
85
211
  //for future use - config schema of the function
@@ -91,3 +217,4 @@ export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps
91
217
 
92
218
  export type BuiltinFunctionName<T extends string = string> = `builtin.${T}`;
93
219
  export type BuiltinDestinationFunctionName = BuiltinFunctionName<`destination.${string}`>;
220
+ export type BuiltinTransformationFunctionName = BuiltinFunctionName<`transformation.${string}`>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/protocols",
3
- "version": "1.1.0-canary.227.20230222142636",
3
+ "version": "1.3.0-canary.231.20230920071611",
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
  }
package/.pnpm-debug.log DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "0 debug pnpm:scope": {
3
- "selected": 1,
4
- "workspacePrefix": "/Users/ildarnurislamov/Projects/onetag"
5
- },
6
- "1 info pnpm": {
7
- "err": {
8
- "name": "Error",
9
- "message": "not found: build",
10
- "code": "ENOENT",
11
- "stack": "Error: not found: build\n at getNotFoundError (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:41714:51)\n at Function.whichSync [as sync] (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:41791:13)\n at getCommandAbsolutePathSync (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:43356:44)\n at default_1 (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:43365:32)\n at /opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:178485:39"
12
- }
13
- },
14
- "2 error pnpm": {
15
- "code": "ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL",
16
- "prefix": "/Users/ildarnurislamov/Projects/onetag/types/jitsu",
17
- "err": {
18
- "name": "pnpm",
19
- "message": "not found: build",
20
- "code": "ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL",
21
- "stack": "Error: not found: build\n at getNotFoundError (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:41714:51)\n at Function.whichSync [as sync] (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:41791:13)\n at getCommandAbsolutePathSync (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:43356:44)\n at default_1 (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:43365:32)\n at /opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:178485:39"
22
- }
23
- }
24
- }