@jitsu/protocols 1.3.1-canary.300.20231019141252 → 1.3.1-canary.300.20231019144955
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-clean.log +1 -1
- package/dist/functions.d.ts +202 -0
- package/dist/functions.js +12 -0
- package/package.json +4 -1
- package/tsconfig.json +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@jitsu/protocols:build: cache hit, replaying output [
|
|
1
|
+
@jitsu/protocols:build: cache hit, replaying output [2m289e72e4051edeb2[0m
|
|
2
2
|
[35m@jitsu/protocols:build: [0m
|
|
3
3
|
[35m@jitsu/protocols:build: [0m> @jitsu/protocols@0.0.0 build /Users/ildarnurislamov/Projects/newjitsu/types/protocols
|
|
4
4
|
[35m@jitsu/protocols:build: [0m> tsc -p .
|
package/.turbo/turbo-clean.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@jitsu/protocols:clean: cache hit, replaying output [
|
|
1
|
+
@jitsu/protocols:clean: cache hit, replaying output [2mbb5c3df4b389eb97[0m
|
|
2
2
|
[35m@jitsu/protocols:clean: [0m
|
|
3
3
|
[35m@jitsu/protocols:clean: [0m> @jitsu/protocols@0.0.0 clean /Users/ildarnurislamov/Projects/newjitsu/types/protocols
|
|
4
4
|
[35m@jitsu/protocols:clean: [0m> rm -rf ./dist
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { AnalyticsServerEvent } from "./analytics";
|
|
2
|
+
export type SetOpts = {
|
|
3
|
+
ttlMs?: number;
|
|
4
|
+
} | {
|
|
5
|
+
ttlSec?: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A key value store that exposed to a function
|
|
9
|
+
*/
|
|
10
|
+
export interface Store {
|
|
11
|
+
get(key: string): Promise<any>;
|
|
12
|
+
del(key: string): Promise<void>;
|
|
13
|
+
set(key: string, value: any, opts?: SetOpts): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Store for incoming events, destination results and function log messages
|
|
17
|
+
*/
|
|
18
|
+
export interface EventsStore {
|
|
19
|
+
log(connectionId: string, error: boolean, msg: Record<string, any>): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A special properties that user can set on an event to define how
|
|
23
|
+
* event will be processed further
|
|
24
|
+
*/
|
|
25
|
+
export type EventControlOpts = {
|
|
26
|
+
/**
|
|
27
|
+
* Table name to store event in. Non-SQL destinations might ignore this property
|
|
28
|
+
*/
|
|
29
|
+
JITSU_TABLE_NAME?: string;
|
|
30
|
+
};
|
|
31
|
+
export type AnyEvent = Record<string, any> & EventControlOpts;
|
|
32
|
+
export type AnyProps = Record<string, any>;
|
|
33
|
+
export type FetchResponse = Response;
|
|
34
|
+
export type FetchType = (url: string, opts?: FetchOpts, logToRedis?: boolean) => Promise<FetchResponse>;
|
|
35
|
+
export type FetchOpts = {
|
|
36
|
+
method?: string;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
body?: string;
|
|
39
|
+
};
|
|
40
|
+
export type FunctionContext = {
|
|
41
|
+
log: {
|
|
42
|
+
info: (message: string, ...args: any[]) => void;
|
|
43
|
+
warn: (message: string, ...args: any[]) => void;
|
|
44
|
+
debug: (message: string, ...args: any[]) => void;
|
|
45
|
+
error: (message: string, ...args: any[]) => void;
|
|
46
|
+
};
|
|
47
|
+
fetch: FetchType;
|
|
48
|
+
store: Store;
|
|
49
|
+
};
|
|
50
|
+
export type PrivacyOpts = {
|
|
51
|
+
/**
|
|
52
|
+
* IP address processing mode
|
|
53
|
+
* "keep" means that the IP address will be kept as is
|
|
54
|
+
* "reduce" means that the IP address will be reduced to the first 3 octets
|
|
55
|
+
* "hash" means that the IP address will be hashed with SHA256 (not implemented yet)
|
|
56
|
+
*
|
|
57
|
+
* "reduce" is the default behavior
|
|
58
|
+
*/
|
|
59
|
+
ip?: "reduce" | "keep" | "hash";
|
|
60
|
+
/**
|
|
61
|
+
* Replaces cookie based anonymous ID with a fingerprint hash
|
|
62
|
+
* "hash1" means that anyonymous ID will be replaced with hash(ip + user_agent)
|
|
63
|
+
*/
|
|
64
|
+
anonymousId?: "hash1" | "keep" | ((opts: {
|
|
65
|
+
ip: string;
|
|
66
|
+
ip3octets: string;
|
|
67
|
+
userAgent: string;
|
|
68
|
+
}) => string);
|
|
69
|
+
};
|
|
70
|
+
export type CoreLib = {
|
|
71
|
+
privacy(event: AnalyticsServerEvent, opts?: PrivacyOpts): AnalyticsServerEvent;
|
|
72
|
+
};
|
|
73
|
+
export type AnonymousEventsStore = {
|
|
74
|
+
addEvent(collectionName: string, anonymousId: string, event: AnalyticsServerEvent, ttlDays: number): Promise<void>;
|
|
75
|
+
evictEvents(collectionName: string, anonymousId: string): Promise<AnalyticsServerEvent[]>;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Function execution context available for builin functions only
|
|
79
|
+
*/
|
|
80
|
+
export type SystemContext = {
|
|
81
|
+
$system: {
|
|
82
|
+
anonymousEventsStore: AnonymousEventsStore;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export type WithConfidence<T> = T & {
|
|
86
|
+
confidence?: number;
|
|
87
|
+
};
|
|
88
|
+
export type Geo = {
|
|
89
|
+
/**
|
|
90
|
+
* IP address of the incoming request
|
|
91
|
+
*/
|
|
92
|
+
continent?: {
|
|
93
|
+
code: "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
|
|
94
|
+
};
|
|
95
|
+
country?: {
|
|
96
|
+
/**
|
|
97
|
+
* Two-letter country code (ISO 3166-1 alpha-2): https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
98
|
+
*/
|
|
99
|
+
code: string;
|
|
100
|
+
isEU: boolean;
|
|
101
|
+
};
|
|
102
|
+
region?: WithConfidence<{
|
|
103
|
+
/**
|
|
104
|
+
* Code of the region (ISO 3166-2): https://en.wikipedia.org/wiki/ISO_3166-2.
|
|
105
|
+
* For USA it's two-letter capitaluzed state code (such as NY)
|
|
106
|
+
*/
|
|
107
|
+
code: string;
|
|
108
|
+
}>;
|
|
109
|
+
city?: WithConfidence<{
|
|
110
|
+
name: string;
|
|
111
|
+
}>;
|
|
112
|
+
postalCode?: WithConfidence<{
|
|
113
|
+
code: string;
|
|
114
|
+
}>;
|
|
115
|
+
location?: {
|
|
116
|
+
latitude: number;
|
|
117
|
+
longitude: number;
|
|
118
|
+
accuracyRadius?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Only for USA locations
|
|
121
|
+
*/
|
|
122
|
+
usaData?: {
|
|
123
|
+
populationDensity?: number;
|
|
124
|
+
metroCode?: number;
|
|
125
|
+
averageIncome?: number;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
provider?: {
|
|
129
|
+
/**
|
|
130
|
+
* Autonomous system number
|
|
131
|
+
*/
|
|
132
|
+
as?: {
|
|
133
|
+
num: number;
|
|
134
|
+
name?: string;
|
|
135
|
+
};
|
|
136
|
+
connectionType?: string;
|
|
137
|
+
domain: string;
|
|
138
|
+
isAnonymousVpn?: boolean;
|
|
139
|
+
isHostingProvider?: boolean;
|
|
140
|
+
isLegitimateProxy?: boolean;
|
|
141
|
+
isPublicProxy?: boolean;
|
|
142
|
+
isResidentialProxy?: boolean;
|
|
143
|
+
isTorExitNode?: boolean;
|
|
144
|
+
userType?: string;
|
|
145
|
+
isp?: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
export type EventContext = {
|
|
149
|
+
/**
|
|
150
|
+
* Geo data of incoming request
|
|
151
|
+
*/
|
|
152
|
+
geo?: Geo;
|
|
153
|
+
/**
|
|
154
|
+
* Headers of incoming request
|
|
155
|
+
*/
|
|
156
|
+
headers: Record<string, string>;
|
|
157
|
+
/**
|
|
158
|
+
* Source of the incoming event
|
|
159
|
+
*/
|
|
160
|
+
source?: {
|
|
161
|
+
id: string;
|
|
162
|
+
name?: string;
|
|
163
|
+
domain?: string;
|
|
164
|
+
};
|
|
165
|
+
destination?: {
|
|
166
|
+
id: string;
|
|
167
|
+
type: string;
|
|
168
|
+
updatedAt: Date;
|
|
169
|
+
hash: string;
|
|
170
|
+
};
|
|
171
|
+
connection?: {
|
|
172
|
+
id: string;
|
|
173
|
+
mode?: string;
|
|
174
|
+
options?: any;
|
|
175
|
+
};
|
|
176
|
+
retries?: number;
|
|
177
|
+
};
|
|
178
|
+
export type FunctionConfigContext<P extends AnyProps = AnyProps> = {
|
|
179
|
+
props: P;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Parameters for a function
|
|
183
|
+
*/
|
|
184
|
+
export type FullContext<P extends AnyProps = AnyProps> = EventContext & FunctionContext & FunctionConfigContext<P> & (SystemContext | {});
|
|
185
|
+
export type FunctionCommand = "drop";
|
|
186
|
+
export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand | false;
|
|
187
|
+
export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps = AnyProps> {
|
|
188
|
+
(event: E, ctx: FullContext<P>): Promise<FuncReturn> | FuncReturn;
|
|
189
|
+
displayName?: string;
|
|
190
|
+
configSchema?: any;
|
|
191
|
+
description?: any;
|
|
192
|
+
}
|
|
193
|
+
export type BuiltinFunctionName<T extends string = string> = `builtin.${T}`;
|
|
194
|
+
export type BuiltinDestinationFunctionName = BuiltinFunctionName<`destination.${string}`>;
|
|
195
|
+
export type BuiltinTransformationFunctionName = BuiltinFunctionName<`transformation.${string}`>;
|
|
196
|
+
export declare const DropRetryErrorName = "Drop & RetryError";
|
|
197
|
+
export declare const RetryErrorName = "RetryError";
|
|
198
|
+
export declare class RetryError extends Error {
|
|
199
|
+
constructor(message?: any, options?: {
|
|
200
|
+
drop: boolean;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RetryError = exports.RetryErrorName = exports.DropRetryErrorName = void 0;
|
|
4
|
+
exports.DropRetryErrorName = "Drop & RetryError";
|
|
5
|
+
exports.RetryErrorName = "RetryError";
|
|
6
|
+
class RetryError extends Error {
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = (options === null || options === void 0 ? void 0 : options.drop) ? `${exports.DropRetryErrorName}` : `${exports.RetryErrorName}`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.RetryError = RetryError;
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/protocols",
|
|
3
|
-
"version": "1.3.1-canary.300.
|
|
3
|
+
"version": "1.3.1-canary.300.20231019144955",
|
|
4
4
|
"description": "",
|
|
5
|
+
"main": "dist/functions.js",
|
|
6
|
+
"module": "dist/functions.js",
|
|
7
|
+
"types": "dist/functions.d.ts",
|
|
5
8
|
"author": "Jitsu Dev Team <dev@jitsu.com>",
|
|
6
9
|
"publishConfig": {
|
|
7
10
|
"access": "public"
|