@jitsu/protocols 1.7.2 → 1.9.0-canary.548.20240108170646

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 CHANGED
@@ -4,6 +4,70 @@ export type ID = string | null | undefined;
4
4
 
5
5
  export type DataLayoutType = "segment" | "jitsu-legacy" | "segment-single-table" | "passthrough";
6
6
 
7
+ export type WithConfidence<T> = T & {
8
+ //A value from 0-100 indicating how confident we are in the result
9
+ confidence?: number;
10
+ };
11
+
12
+ export type Geo = {
13
+ continent?: {
14
+ code: "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
15
+ };
16
+ country?: {
17
+ /**
18
+ * Two-letter country code (ISO 3166-1 alpha-2): https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
19
+ */
20
+ code: string;
21
+ isEU: boolean;
22
+ };
23
+ region?: WithConfidence<{
24
+ /**
25
+ * Code of the region (ISO 3166-2): https://en.wikipedia.org/wiki/ISO_3166-2.
26
+ * For USA it's two-letter capitaluzed state code (such as NY)
27
+ */
28
+ code: string;
29
+ }>;
30
+ city?: WithConfidence<{
31
+ name: string;
32
+ }>;
33
+
34
+ postalCode?: WithConfidence<{
35
+ code: string;
36
+ }>;
37
+
38
+ location?: {
39
+ latitude: number;
40
+ longitude: number;
41
+ accuracyRadius?: number;
42
+ /**
43
+ * Only for USA locations
44
+ */
45
+ usaData?: {
46
+ populationDensity?: number;
47
+ metroCode?: number;
48
+ averageIncome?: number;
49
+ };
50
+ };
51
+ provider?: {
52
+ /**
53
+ * Autonomous system number
54
+ */
55
+ as?: {
56
+ num?: number;
57
+ name?: string;
58
+ };
59
+ connectionType?: string;
60
+ domain?: string;
61
+ isAnonymousVpn?: boolean;
62
+ isHostingProvider?: boolean;
63
+ isLegitimateProxy?: boolean;
64
+ isPublicProxy?: boolean;
65
+ isResidentialProxy?: boolean;
66
+ isTorExitNode?: boolean;
67
+ userType?: string;
68
+ isp?: string;
69
+ };
70
+ };
7
71
  /**
8
72
  * Event coming from client library
9
73
  */
@@ -43,7 +107,7 @@ export type ServerContextReservedProps = {
43
107
  //if request came server-to-server, then it's an IP of a server
44
108
  //for device events it will be an IP of a device
45
109
  //don't use this field in functions, use context.ip instead
46
- request_ip?: string;
110
+ requestIp?: string;
47
111
  receivedAt?: ISO8601Date;
48
112
  sentAt?: ISO8601Date;
49
113
  timestamp?: ISO8601Date;
@@ -63,7 +127,7 @@ interface ProcessingContext {
63
127
 
64
128
  export type AnalyticsServerEvent = AnalyticsClientEvent & ServerContext & ProcessingContext;
65
129
 
66
- export type JSONPrimitive = string | number | boolean | null;
130
+ export type JSONPrimitive = string | number | boolean | null | undefined;
67
131
  export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
68
132
  export type JSONObject = { [member: string]: JSONValue };
69
133
  export type JSONArray = Array<JSONValue>;
@@ -108,7 +172,7 @@ export type PageReservedProps = {
108
172
  interface AnalyticsContext {
109
173
  /**
110
174
  * 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)
175
+ * (copied from requestIp)
112
176
  * If request is sent from server-to-server, this field is not automatically populated
113
177
  * and should be filled manually
114
178
  */
@@ -126,6 +190,8 @@ interface AnalyticsContext {
126
190
  library?: {
127
191
  name: string;
128
192
  version: string;
193
+ //allow to add custom fields
194
+ [key: string]: any;
129
195
  };
130
196
 
131
197
  traits?: { crossDomainId?: string } & JSONObject;
@@ -154,7 +220,7 @@ interface AnalyticsContext {
154
220
  //Client ID of GA4 property
155
221
  ga4?: {
156
222
  clientId: string;
157
- sessions?: Record<string, string>;
223
+ sessionIds?: any;
158
224
  };
159
225
  //from cookies: _fbc - Facebook click ID, _fbp - Facebook browser ID.
160
226
  //see https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
@@ -162,6 +228,45 @@ interface AnalyticsContext {
162
228
  fbp?: string;
163
229
  };
164
230
 
231
+ geo?: Geo;
232
+
233
+ //mobile
234
+ app?: {
235
+ name: string;
236
+ version: string;
237
+ build?: string;
238
+ namespace?: string;
239
+ [key: string]: any;
240
+ };
241
+ device?: {
242
+ id?: string;
243
+ advertisingId?: string;
244
+ adTrackingEnabled?: boolean;
245
+ manufacturer?: string;
246
+ model?: string;
247
+ name?: string;
248
+ type?: string;
249
+ token?: string;
250
+ [key: string]: any;
251
+ };
252
+ network?: {
253
+ bluetooth?: boolean;
254
+ carrier?: string;
255
+ cellular?: boolean;
256
+ wifi?: boolean;
257
+ [key: string]: any;
258
+ };
259
+ os?: {
260
+ name: string;
261
+ version: string;
262
+ };
263
+ screen?: {
264
+ width: number;
265
+ height: number;
266
+ density?: number;
267
+ [key: string]: any;
268
+ };
269
+
165
270
  [key: string]: any;
166
271
  }
167
272
 
@@ -1,5 +1,5 @@
1
1
  import { ISO8601Date } from "./iso8601";
2
- import type { Geo } from "./functions";
2
+ import type { Geo } from "./analytics";
3
3
 
4
4
  export type IngestType = "s2s" | "browser";
5
5
 
@@ -9,7 +9,10 @@ export type IngestMessage = {
9
9
  messageCreated: ISO8601Date;
10
10
  writeKey: string;
11
11
  messageId: string;
12
+ //currently this not being filled
12
13
  connectionId: string;
14
+ //id of a stream where this message should eventually go. For debugging purposes so far
15
+ streamId?: string;
13
16
  type: string;
14
17
  origin: {
15
18
  baseUrl: string;
package/functions.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnalyticsServerEvent } from "./analytics";
1
+ import { AnalyticsServerEvent, Geo } from "./analytics";
2
2
 
3
3
  /**
4
4
  * Store set options: ttl in seconds or string representation of duration (e.g. "1d")
@@ -15,6 +15,10 @@ export interface Store {
15
15
  ttl(key: string): Promise<number>;
16
16
  }
17
17
 
18
+ export interface TTLStore extends Store {
19
+ getWithTTL(key: string): Promise<{ value: any; ttl: number } | undefined>;
20
+ }
21
+
18
22
  /**
19
23
  * Store for incoming events, destination results and function log messages
20
24
  */
@@ -44,13 +48,14 @@ export type FetchOpts = {
44
48
  headers?: Record<string, string>;
45
49
  body?: string;
46
50
  };
51
+ export type FunctionLogger = {
52
+ info: (message: string, ...args: any[]) => void;
53
+ warn: (message: string, ...args: any[]) => void;
54
+ debug: (message: string, ...args: any[]) => void;
55
+ error: (message: string, ...args: any[]) => void;
56
+ };
47
57
  export type FunctionContext = {
48
- log: {
49
- info: (message: string, ...args: any[]) => void;
50
- warn: (message: string, ...args: any[]) => void;
51
- debug: (message: string, ...args: any[]) => void;
52
- error: (message: string, ...args: any[]) => void;
53
- };
58
+ log: FunctionLogger;
54
59
  fetch: FetchType;
55
60
  store: Store;
56
61
  };
@@ -81,74 +86,6 @@ export type AnonymousEventsStore = {
81
86
  evictEvents(collectionName: string, anonymousId: string): Promise<AnalyticsServerEvent[]>;
82
87
  };
83
88
 
84
- export type WithConfidence<T> = T & {
85
- //A value from 0-100 indicating how confident we are in the result
86
- confidence?: number;
87
- };
88
-
89
- export type Geo = {
90
- /**
91
- * IP address of the incoming request
92
- */
93
- continent?: {
94
- code: "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
95
- };
96
- country?: {
97
- /**
98
- * Two-letter country code (ISO 3166-1 alpha-2): https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
99
- */
100
- code: string;
101
- isEU: boolean;
102
- };
103
- region?: WithConfidence<{
104
- /**
105
- * Code of the region (ISO 3166-2): https://en.wikipedia.org/wiki/ISO_3166-2.
106
- * For USA it's two-letter capitaluzed state code (such as NY)
107
- */
108
- code: string;
109
- }>;
110
- city?: WithConfidence<{
111
- name: string;
112
- }>;
113
-
114
- postalCode?: WithConfidence<{
115
- code: string;
116
- }>;
117
-
118
- location?: {
119
- latitude: number;
120
- longitude: number;
121
- accuracyRadius?: number;
122
- /**
123
- * Only for USA locations
124
- */
125
- usaData?: {
126
- populationDensity?: number;
127
- metroCode?: number;
128
- averageIncome?: number;
129
- };
130
- };
131
- provider?: {
132
- /**
133
- * Autonomous system number
134
- */
135
- as?: {
136
- num: number;
137
- name?: string;
138
- };
139
- connectionType?: string;
140
- domain: string;
141
- isAnonymousVpn?: boolean;
142
- isHostingProvider?: boolean;
143
- isLegitimateProxy?: boolean;
144
- isPublicProxy?: boolean;
145
- isResidentialProxy?: boolean;
146
- isTorExitNode?: boolean;
147
- userType?: string;
148
- isp?: string;
149
- };
150
- };
151
-
152
89
  export type UserAgent = {
153
90
  browser: {
154
91
  name: string;
@@ -193,12 +130,14 @@ export type EventContext = {
193
130
  source: {
194
131
  id: string;
195
132
  name?: string;
133
+ //if request was sent from browser or server-to-server api
134
+ type: "browser" | "s2s";
196
135
  domain?: string;
197
136
  };
198
137
  destination: {
199
138
  id: string;
200
139
  type: string;
201
- updatedAt: Date;
140
+ updatedAt?: Date;
202
141
  hash: string;
203
142
  };
204
143
  connection: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/protocols",
3
- "version": "1.7.2",
3
+ "version": "1.9.0-canary.548.20240108170646",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "publishConfig": {