@jitsu/protocols 1.2.0 → 1.3.0-canary.231.20230920071735

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
@@ -1,8 +1,10 @@
1
1
  import { ISO8601Date } from "./iso8601";
2
+ import { Geo } from "./functions";
2
3
 
3
4
  export type IngestType = "s2s" | "browser";
4
5
 
5
6
  export type IngestMessage = {
7
+ geo?: Geo;
6
8
  ingestType: IngestType;
7
9
  messageCreated: ISO8601Date;
8
10
  writeKey: string;
package/functions.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { AnalyticsServerEvent } from "./analytics";
2
- import { RequestOptions } from "http";
3
2
 
4
3
  export type SetOpts = { ttlMs?: number } | { ttlSec?: number };
5
4
 
@@ -16,9 +15,8 @@ interface Store {
16
15
  * Store for incoming events, destination results and function log messages
17
16
  */
18
17
  interface EventsStore {
19
- log(error: boolean, msg: Record<string, any>): Promise<void>;
18
+ log(connectionId: string, error: boolean, msg: Record<string, any>): void;
20
19
  }
21
-
22
20
  /**
23
21
  * A special properties that user can set on an event to define how
24
22
  * event will be processed further
@@ -43,7 +41,6 @@ export type FetchResponse = {
43
41
  export type FetchOpts = {
44
42
  method?: string;
45
43
  headers?: Record<string, string>;
46
- agent?: RequestOptions["agent"] | ((parsedUrl: URL) => RequestOptions["agent"]);
47
44
  body?: string;
48
45
  };
49
46
  export type FunctionContext = {
@@ -57,6 +54,27 @@ export type FunctionContext = {
57
54
  store: Store;
58
55
  };
59
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
+
60
78
  export type AnonymousEventsStore = {
61
79
  addEvent(collectionName: string, anonymousId: string, event: AnalyticsServerEvent, ttlDays: number): Promise<void>;
62
80
  evictEvents(collectionName: string, anonymousId: string): Promise<AnalyticsServerEvent[]>;
@@ -71,7 +89,79 @@ export type SystemContext = {
71
89
  };
72
90
  };
73
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
+
74
160
  export type EventContext = {
161
+ /**
162
+ * Geo data of incoming request
163
+ */
164
+ geo?: Geo;
75
165
  /**
76
166
  * Headers of incoming request
77
167
  */
@@ -112,7 +202,7 @@ export type FullContext<P extends AnyProps = AnyProps> = EventContext &
112
202
  //equivalent to returning [] from a function
113
203
  export type FunctionCommand = "drop";
114
204
 
115
- export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand;
205
+ export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand | false;
116
206
 
117
207
  export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps = AnyProps> {
118
208
  (event: E, ctx: FullContext<P>): Promise<FuncReturn> | FuncReturn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/protocols",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-canary.231.20230920071735",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "publishConfig": {