@jitsu/protocols 1.9.0-canary.581.20240115194116 → 1.9.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/functions.d.ts +25 -15
- package/package.json +1 -1
package/functions.d.ts
CHANGED
|
@@ -37,12 +37,6 @@ export interface TTLStore extends Store {
|
|
|
37
37
|
getWithTTL(key: string): Promise<{ value: any; ttl: number } | undefined>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
41
|
-
* Store for incoming events, destination results and function log messages
|
|
42
|
-
*/
|
|
43
|
-
export interface EventsStore {
|
|
44
|
-
log(connectionId: string, error: boolean, msg: Record<string, any>): void;
|
|
45
|
-
}
|
|
46
40
|
/**
|
|
47
41
|
* A special properties that user can set on an event to define how
|
|
48
42
|
* event will be processed further
|
|
@@ -59,24 +53,24 @@ export type AnyProps = Record<string, any>;
|
|
|
59
53
|
|
|
60
54
|
export type FetchResponse = Response;
|
|
61
55
|
|
|
62
|
-
export type FetchType = (url: string, opts?: FetchOpts,
|
|
56
|
+
export type FetchType = (url: string, opts?: FetchOpts, extras?: any) => Promise<FetchResponse>;
|
|
63
57
|
|
|
64
58
|
export type FetchOpts = {
|
|
65
59
|
method?: string;
|
|
66
60
|
headers?: Record<string, string>;
|
|
67
|
-
body?: string;
|
|
61
|
+
body?: string | Buffer;
|
|
68
62
|
};
|
|
69
|
-
export type FunctionLogger = {
|
|
70
|
-
info: (message: string, ...args: any[]) => void
|
|
71
|
-
warn: (message: string, ...args: any[]) => void
|
|
72
|
-
debug: (message: string, ...args: any[]) => void
|
|
73
|
-
error: (message: string, ...args: any[]) => void
|
|
63
|
+
export type FunctionLogger<Sync extends boolean = false> = {
|
|
64
|
+
info: (message: string, ...args: any[]) => void | Promise<void>;
|
|
65
|
+
warn: (message: string, ...args: any[]) => void | Promise<void>;
|
|
66
|
+
debug: (message: string, ...args: any[]) => void | Promise<void>;
|
|
67
|
+
error: (message: string, ...args: any[]) => void | Promise<void>;
|
|
74
68
|
};
|
|
75
69
|
export type FunctionContext = {
|
|
76
70
|
log: FunctionLogger;
|
|
77
71
|
fetch: FetchType;
|
|
78
|
-
store:
|
|
79
|
-
metrics
|
|
72
|
+
store: TTLStore;
|
|
73
|
+
metrics?: Metrics;
|
|
80
74
|
};
|
|
81
75
|
|
|
82
76
|
export type PrivacyOpts = {
|
|
@@ -164,6 +158,9 @@ export type EventContext = {
|
|
|
164
158
|
mode?: string;
|
|
165
159
|
options?: any;
|
|
166
160
|
};
|
|
161
|
+
workspace: {
|
|
162
|
+
id: string;
|
|
163
|
+
};
|
|
167
164
|
// number of retries attempted
|
|
168
165
|
retries?: number;
|
|
169
166
|
};
|
|
@@ -182,6 +179,19 @@ export type FunctionCommand = "drop";
|
|
|
182
179
|
|
|
183
180
|
export type FuncReturn = AnyEvent[] | AnyEvent | null | undefined | FunctionCommand | false;
|
|
184
181
|
|
|
182
|
+
export type SyncFunction<
|
|
183
|
+
Dest extends AnyProps = AnyProps,
|
|
184
|
+
Cred extends AnyProps = AnyProps,
|
|
185
|
+
SyncProps extends AnyProps = AnyProps
|
|
186
|
+
> = (p: {
|
|
187
|
+
source: { package: string; credentials: Cred; syncProps: SyncProps };
|
|
188
|
+
destination: Dest;
|
|
189
|
+
ctx: {
|
|
190
|
+
log: FunctionLogger;
|
|
191
|
+
store: Store;
|
|
192
|
+
};
|
|
193
|
+
}) => Promise<void>;
|
|
194
|
+
|
|
185
195
|
export interface JitsuFunction<E extends AnyEvent = AnyEvent, P extends AnyProps = AnyProps> {
|
|
186
196
|
(event: E, ctx: FullContext<P>): Promise<FuncReturn> | FuncReturn;
|
|
187
197
|
|