@walkeros/server-destination-reddit 3.4.0-next-1776749829492
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/README.md +137 -0
- package/dist/dev.d.mts +115 -0
- package/dist/dev.d.ts +115 -0
- package/dist/dev.js +1 -0
- package/dist/dev.js.map +1 -0
- package/dist/dev.mjs +1 -0
- package/dist/dev.mjs.map +1 -0
- package/dist/examples/index.d.mts +40 -0
- package/dist/examples/index.d.ts +40 -0
- package/dist/examples/index.js +401 -0
- package/dist/examples/index.mjs +379 -0
- package/dist/index.d.mts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/walkerOS.json +621 -0
- package/package.json +75 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/examples/env.ts
|
|
8
|
+
var env_exports = {};
|
|
9
|
+
__export(env_exports, {
|
|
10
|
+
push: () => push,
|
|
11
|
+
simulation: () => simulation
|
|
12
|
+
});
|
|
13
|
+
var mockSendServer = async () => {
|
|
14
|
+
return {
|
|
15
|
+
ok: true,
|
|
16
|
+
data: {
|
|
17
|
+
success: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var push = {
|
|
22
|
+
sendServer: mockSendServer
|
|
23
|
+
};
|
|
24
|
+
var simulation = ["sendServer"];
|
|
25
|
+
|
|
26
|
+
// src/examples/step.ts
|
|
27
|
+
var step_exports = {};
|
|
28
|
+
__export(step_exports, {
|
|
29
|
+
addToCart: () => addToCart,
|
|
30
|
+
lead: () => lead,
|
|
31
|
+
pageVisit: () => pageVisit,
|
|
32
|
+
purchase: () => purchase,
|
|
33
|
+
search: () => search,
|
|
34
|
+
signUp: () => signUp
|
|
35
|
+
});
|
|
36
|
+
import { getEvent, isObject } from "@walkeros/core";
|
|
37
|
+
var ENDPOINT = "https://ads-api.reddit.com/api/v2.0/conversions/events/a2_abcdef123456";
|
|
38
|
+
var OPTIONS = {
|
|
39
|
+
headers: { Authorization: "Bearer s3cr3t" }
|
|
40
|
+
};
|
|
41
|
+
var purchase = {
|
|
42
|
+
in: getEvent("order complete", {
|
|
43
|
+
timestamp: 1700000900,
|
|
44
|
+
data: { id: "ORD-300", total: 249.99, currency: "EUR" },
|
|
45
|
+
nested: [
|
|
46
|
+
{
|
|
47
|
+
entity: "product",
|
|
48
|
+
data: {
|
|
49
|
+
id: "SKU-A1",
|
|
50
|
+
name: "Everyday Ruck Snack",
|
|
51
|
+
category: "bags",
|
|
52
|
+
price: "129.99",
|
|
53
|
+
quantity: 2
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
user: { id: "user-123", device: "device-456" },
|
|
58
|
+
source: { type: "server", id: "https://shop.example.com", previous_id: "" }
|
|
59
|
+
}),
|
|
60
|
+
mapping: {
|
|
61
|
+
name: "Purchase",
|
|
62
|
+
data: {
|
|
63
|
+
map: {
|
|
64
|
+
event_metadata: {
|
|
65
|
+
map: {
|
|
66
|
+
value_decimal: "data.total",
|
|
67
|
+
currency: { key: "data.currency", value: "EUR" },
|
|
68
|
+
item_count: {
|
|
69
|
+
fn: (event) => event.nested.filter(
|
|
70
|
+
(item) => item.entity === "product"
|
|
71
|
+
).length
|
|
72
|
+
},
|
|
73
|
+
products: {
|
|
74
|
+
loop: [
|
|
75
|
+
"nested",
|
|
76
|
+
{
|
|
77
|
+
condition: (entity) => isObject(entity) && entity.entity === "product",
|
|
78
|
+
map: {
|
|
79
|
+
id: "data.id",
|
|
80
|
+
name: "data.name",
|
|
81
|
+
category: { key: "data.category", value: "uncategorized" }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
out: [
|
|
92
|
+
[
|
|
93
|
+
"sendServer",
|
|
94
|
+
ENDPOINT,
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
data: {
|
|
97
|
+
events: [
|
|
98
|
+
{
|
|
99
|
+
event_at: "1970-01-20T16:13:20.900Z",
|
|
100
|
+
event_at_ms: 1700000900,
|
|
101
|
+
event_type: { tracking_type: "Purchase" },
|
|
102
|
+
user: {},
|
|
103
|
+
event_metadata: {
|
|
104
|
+
conversion_id: "1700000900-gr0up-1",
|
|
105
|
+
value_decimal: 249.99,
|
|
106
|
+
currency: "EUR",
|
|
107
|
+
item_count: 1,
|
|
108
|
+
products: [
|
|
109
|
+
{
|
|
110
|
+
id: "SKU-A1",
|
|
111
|
+
name: "Everyday Ruck Snack",
|
|
112
|
+
category: "bags"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
OPTIONS
|
|
121
|
+
]
|
|
122
|
+
]
|
|
123
|
+
};
|
|
124
|
+
var addToCart = {
|
|
125
|
+
in: getEvent("product add", {
|
|
126
|
+
timestamp: 1700000901,
|
|
127
|
+
data: {
|
|
128
|
+
id: "SKU-B2",
|
|
129
|
+
name: "Cool Cap",
|
|
130
|
+
category: "hats",
|
|
131
|
+
price: "42.00",
|
|
132
|
+
quantity: 1
|
|
133
|
+
},
|
|
134
|
+
user: { id: "user-456" },
|
|
135
|
+
source: {
|
|
136
|
+
type: "server",
|
|
137
|
+
id: "https://shop.example.com/products",
|
|
138
|
+
previous_id: ""
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
mapping: {
|
|
142
|
+
name: "AddToCart",
|
|
143
|
+
data: {
|
|
144
|
+
map: {
|
|
145
|
+
event_metadata: {
|
|
146
|
+
map: {
|
|
147
|
+
value_decimal: "data.price",
|
|
148
|
+
currency: { value: "EUR" },
|
|
149
|
+
item_count: { value: 1 },
|
|
150
|
+
products: {
|
|
151
|
+
set: [
|
|
152
|
+
{
|
|
153
|
+
map: {
|
|
154
|
+
id: "data.id",
|
|
155
|
+
name: "data.name",
|
|
156
|
+
category: { key: "data.category", value: "uncategorized" }
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
out: [
|
|
167
|
+
[
|
|
168
|
+
"sendServer",
|
|
169
|
+
ENDPOINT,
|
|
170
|
+
JSON.stringify({
|
|
171
|
+
data: {
|
|
172
|
+
events: [
|
|
173
|
+
{
|
|
174
|
+
event_at: "1970-01-20T16:13:20.901Z",
|
|
175
|
+
event_at_ms: 1700000901,
|
|
176
|
+
event_type: { tracking_type: "AddToCart" },
|
|
177
|
+
user: {},
|
|
178
|
+
event_metadata: {
|
|
179
|
+
conversion_id: "1700000901-gr0up-1",
|
|
180
|
+
value_decimal: "42.00",
|
|
181
|
+
currency: "EUR",
|
|
182
|
+
item_count: 1,
|
|
183
|
+
products: [
|
|
184
|
+
{ id: "SKU-B2", name: "Cool Cap", category: "hats" }
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
OPTIONS
|
|
192
|
+
]
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
var pageVisit = {
|
|
196
|
+
in: getEvent("page view", {
|
|
197
|
+
timestamp: 1700000902,
|
|
198
|
+
user: { id: "user-789" },
|
|
199
|
+
source: {
|
|
200
|
+
type: "server",
|
|
201
|
+
id: "https://www.example.com/docs/",
|
|
202
|
+
previous_id: ""
|
|
203
|
+
}
|
|
204
|
+
}),
|
|
205
|
+
mapping: {
|
|
206
|
+
name: "PageVisit"
|
|
207
|
+
},
|
|
208
|
+
out: [
|
|
209
|
+
[
|
|
210
|
+
"sendServer",
|
|
211
|
+
ENDPOINT,
|
|
212
|
+
JSON.stringify({
|
|
213
|
+
data: {
|
|
214
|
+
events: [
|
|
215
|
+
{
|
|
216
|
+
event_at: "1970-01-20T16:13:20.902Z",
|
|
217
|
+
event_at_ms: 1700000902,
|
|
218
|
+
event_type: { tracking_type: "PageVisit" },
|
|
219
|
+
user: {},
|
|
220
|
+
event_metadata: { conversion_id: "1700000902-gr0up-1" }
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
}),
|
|
225
|
+
OPTIONS
|
|
226
|
+
]
|
|
227
|
+
]
|
|
228
|
+
};
|
|
229
|
+
var lead = {
|
|
230
|
+
in: getEvent("form submit", {
|
|
231
|
+
timestamp: 1700000903,
|
|
232
|
+
data: { form: "contact" },
|
|
233
|
+
user: { id: "user-lead-1", email: "lead@example.com" },
|
|
234
|
+
source: {
|
|
235
|
+
type: "server",
|
|
236
|
+
id: "https://www.example.com/contact",
|
|
237
|
+
previous_id: ""
|
|
238
|
+
}
|
|
239
|
+
}),
|
|
240
|
+
mapping: {
|
|
241
|
+
name: "Lead",
|
|
242
|
+
data: {
|
|
243
|
+
map: {
|
|
244
|
+
user: {
|
|
245
|
+
map: {
|
|
246
|
+
email: "user.email",
|
|
247
|
+
external_id: "user.id"
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
out: [
|
|
254
|
+
[
|
|
255
|
+
"sendServer",
|
|
256
|
+
ENDPOINT,
|
|
257
|
+
JSON.stringify({
|
|
258
|
+
data: {
|
|
259
|
+
events: [
|
|
260
|
+
{
|
|
261
|
+
event_at: "1970-01-20T16:13:20.903Z",
|
|
262
|
+
event_at_ms: 1700000903,
|
|
263
|
+
event_type: { tracking_type: "Lead" },
|
|
264
|
+
user: {
|
|
265
|
+
// sha256('lead@example.com')
|
|
266
|
+
email: "9fbdefe2837a03c9225be80e741f316f4d174d1732b719b6abb6477efc1ae9d2",
|
|
267
|
+
// sha256('user-lead-1')
|
|
268
|
+
external_id: "ee818eebb052cf288ffeeb2e09ee35c9946e1a7f53a959cb3ef06d5d4adb78e8"
|
|
269
|
+
},
|
|
270
|
+
event_metadata: { conversion_id: "1700000903-gr0up-1" }
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
}),
|
|
275
|
+
OPTIONS
|
|
276
|
+
]
|
|
277
|
+
]
|
|
278
|
+
};
|
|
279
|
+
var signUp = {
|
|
280
|
+
in: getEvent("user signup", {
|
|
281
|
+
timestamp: 1700000904,
|
|
282
|
+
data: { method: "email" },
|
|
283
|
+
user: { id: "new-user-1", email: "new@example.com" },
|
|
284
|
+
source: {
|
|
285
|
+
type: "server",
|
|
286
|
+
id: "https://www.example.com/register",
|
|
287
|
+
previous_id: ""
|
|
288
|
+
}
|
|
289
|
+
}),
|
|
290
|
+
mapping: {
|
|
291
|
+
name: "SignUp",
|
|
292
|
+
data: {
|
|
293
|
+
map: {
|
|
294
|
+
user: {
|
|
295
|
+
map: {
|
|
296
|
+
email: "user.email",
|
|
297
|
+
external_id: "user.id"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
out: [
|
|
304
|
+
[
|
|
305
|
+
"sendServer",
|
|
306
|
+
ENDPOINT,
|
|
307
|
+
JSON.stringify({
|
|
308
|
+
data: {
|
|
309
|
+
events: [
|
|
310
|
+
{
|
|
311
|
+
event_at: "1970-01-20T16:13:20.904Z",
|
|
312
|
+
event_at_ms: 1700000904,
|
|
313
|
+
event_type: { tracking_type: "SignUp" },
|
|
314
|
+
user: {
|
|
315
|
+
// sha256('new@example.com')
|
|
316
|
+
email: "f0030501023327437b06e5c6f87df7871b8e704ae608d1d0b7b24fdd2a06c716",
|
|
317
|
+
// sha256('new-user-1')
|
|
318
|
+
external_id: "b45cf5f6ebc2c6974ea3bd9fab19f8cc3a7cf63054727a9fcd22f1fda97d6dde"
|
|
319
|
+
},
|
|
320
|
+
event_metadata: { conversion_id: "1700000904-gr0up-1" }
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
}),
|
|
325
|
+
OPTIONS
|
|
326
|
+
]
|
|
327
|
+
]
|
|
328
|
+
};
|
|
329
|
+
var search = {
|
|
330
|
+
in: getEvent("site search", {
|
|
331
|
+
timestamp: 1700000905,
|
|
332
|
+
data: { query: "walkerOS destinations" },
|
|
333
|
+
user: { id: "user-101" },
|
|
334
|
+
source: {
|
|
335
|
+
type: "server",
|
|
336
|
+
id: "https://www.example.com/search",
|
|
337
|
+
previous_id: ""
|
|
338
|
+
}
|
|
339
|
+
}),
|
|
340
|
+
mapping: {
|
|
341
|
+
name: "Search",
|
|
342
|
+
data: {
|
|
343
|
+
map: {
|
|
344
|
+
event_metadata: {
|
|
345
|
+
map: {
|
|
346
|
+
item_count: { value: 1 }
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
out: [
|
|
353
|
+
[
|
|
354
|
+
"sendServer",
|
|
355
|
+
ENDPOINT,
|
|
356
|
+
JSON.stringify({
|
|
357
|
+
data: {
|
|
358
|
+
events: [
|
|
359
|
+
{
|
|
360
|
+
event_at: "1970-01-20T16:13:20.905Z",
|
|
361
|
+
event_at_ms: 1700000905,
|
|
362
|
+
event_type: { tracking_type: "Search" },
|
|
363
|
+
user: {},
|
|
364
|
+
event_metadata: {
|
|
365
|
+
conversion_id: "1700000905-gr0up-1",
|
|
366
|
+
item_count: 1
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
]
|
|
370
|
+
}
|
|
371
|
+
}),
|
|
372
|
+
OPTIONS
|
|
373
|
+
]
|
|
374
|
+
]
|
|
375
|
+
};
|
|
376
|
+
export {
|
|
377
|
+
env_exports as env,
|
|
378
|
+
step_exports as step
|
|
379
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Mapping as Mapping$1, Destination as Destination$1 } from '@walkeros/core';
|
|
2
|
+
import { DestinationServer, sendServer } from '@walkeros/server-core';
|
|
3
|
+
|
|
4
|
+
interface Settings {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
pixelId: string;
|
|
7
|
+
action_source?: ActionSource;
|
|
8
|
+
doNotHash?: string[];
|
|
9
|
+
test_mode?: boolean;
|
|
10
|
+
url?: string;
|
|
11
|
+
user_data?: Mapping$1.Map;
|
|
12
|
+
}
|
|
13
|
+
type InitSettings = Partial<Settings>;
|
|
14
|
+
interface Mapping {
|
|
15
|
+
}
|
|
16
|
+
interface Env extends DestinationServer.Env {
|
|
17
|
+
sendServer?: typeof sendServer;
|
|
18
|
+
}
|
|
19
|
+
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
20
|
+
interface Destination extends DestinationServer.Destination<Types> {
|
|
21
|
+
init: DestinationServer.InitFn<Types>;
|
|
22
|
+
}
|
|
23
|
+
type Config = {
|
|
24
|
+
settings: Settings;
|
|
25
|
+
} & DestinationServer.Config<Types>;
|
|
26
|
+
type InitFn = DestinationServer.InitFn<Types>;
|
|
27
|
+
type PushFn = DestinationServer.PushFn<Types>;
|
|
28
|
+
type PartialConfig = DestinationServer.PartialConfig<Types>;
|
|
29
|
+
type PushEvents = DestinationServer.PushEvents<Mapping>;
|
|
30
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
31
|
+
type Rules = Mapping$1.Rules<Rule>;
|
|
32
|
+
type ActionSource = 'WEBSITE' | 'APP' | 'PHYSICAL_STORE';
|
|
33
|
+
type TrackingType = 'PageVisit' | 'ViewContent' | 'Search' | 'AddToCart' | 'AddToWishlist' | 'Purchase' | 'Lead' | 'SignUp' | 'Custom';
|
|
34
|
+
interface EventType {
|
|
35
|
+
tracking_type: TrackingType;
|
|
36
|
+
custom_event_name?: string;
|
|
37
|
+
}
|
|
38
|
+
interface Product {
|
|
39
|
+
id: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
category: string;
|
|
42
|
+
}
|
|
43
|
+
interface EventMetadata {
|
|
44
|
+
conversion_id?: string;
|
|
45
|
+
item_count?: number;
|
|
46
|
+
currency?: string;
|
|
47
|
+
value?: number;
|
|
48
|
+
value_decimal?: number;
|
|
49
|
+
products?: Product[];
|
|
50
|
+
units_sold?: number;
|
|
51
|
+
country_code?: string;
|
|
52
|
+
}
|
|
53
|
+
interface ScreenDimensions {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
}
|
|
57
|
+
interface DataProcessingOptions {
|
|
58
|
+
modes: string[];
|
|
59
|
+
country?: string;
|
|
60
|
+
region?: string;
|
|
61
|
+
}
|
|
62
|
+
interface UserData {
|
|
63
|
+
email?: string;
|
|
64
|
+
external_id?: string;
|
|
65
|
+
ip_address?: string;
|
|
66
|
+
user_agent?: string;
|
|
67
|
+
idfa?: string;
|
|
68
|
+
aaid?: string;
|
|
69
|
+
uuid?: string;
|
|
70
|
+
opt_out?: boolean;
|
|
71
|
+
screen_dimensions?: ScreenDimensions;
|
|
72
|
+
data_processing_options?: DataProcessingOptions;
|
|
73
|
+
}
|
|
74
|
+
interface ConversionEvent {
|
|
75
|
+
click_id?: string;
|
|
76
|
+
event_at: string;
|
|
77
|
+
event_at_ms?: number;
|
|
78
|
+
event_type: EventType;
|
|
79
|
+
event_metadata?: EventMetadata;
|
|
80
|
+
user: UserData;
|
|
81
|
+
}
|
|
82
|
+
interface RequestBody {
|
|
83
|
+
test_mode?: boolean;
|
|
84
|
+
data: {
|
|
85
|
+
events: ConversionEvent[];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
interface ResponseBody {
|
|
89
|
+
success?: boolean;
|
|
90
|
+
message?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type index_ActionSource = ActionSource;
|
|
94
|
+
type index_Config = Config;
|
|
95
|
+
type index_ConversionEvent = ConversionEvent;
|
|
96
|
+
type index_DataProcessingOptions = DataProcessingOptions;
|
|
97
|
+
type index_Destination = Destination;
|
|
98
|
+
type index_Env = Env;
|
|
99
|
+
type index_EventMetadata = EventMetadata;
|
|
100
|
+
type index_EventType = EventType;
|
|
101
|
+
type index_InitFn = InitFn;
|
|
102
|
+
type index_InitSettings = InitSettings;
|
|
103
|
+
type index_Mapping = Mapping;
|
|
104
|
+
type index_PartialConfig = PartialConfig;
|
|
105
|
+
type index_Product = Product;
|
|
106
|
+
type index_PushEvents = PushEvents;
|
|
107
|
+
type index_PushFn = PushFn;
|
|
108
|
+
type index_RequestBody = RequestBody;
|
|
109
|
+
type index_ResponseBody = ResponseBody;
|
|
110
|
+
type index_Rule = Rule;
|
|
111
|
+
type index_Rules = Rules;
|
|
112
|
+
type index_ScreenDimensions = ScreenDimensions;
|
|
113
|
+
type index_Settings = Settings;
|
|
114
|
+
type index_TrackingType = TrackingType;
|
|
115
|
+
type index_Types = Types;
|
|
116
|
+
type index_UserData = UserData;
|
|
117
|
+
declare namespace index {
|
|
118
|
+
export type { index_ActionSource as ActionSource, index_Config as Config, index_ConversionEvent as ConversionEvent, index_DataProcessingOptions as DataProcessingOptions, index_Destination as Destination, index_Env as Env, index_EventMetadata as EventMetadata, index_EventType as EventType, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_Product as Product, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RequestBody as RequestBody, index_ResponseBody as ResponseBody, index_Rule as Rule, index_Rules as Rules, index_ScreenDimensions as ScreenDimensions, index_Settings as Settings, index_TrackingType as TrackingType, index_Types as Types, index_UserData as UserData };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare const destinationReddit: Destination;
|
|
122
|
+
|
|
123
|
+
export { index as DestinationReddit, destinationReddit as default, destinationReddit };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Mapping as Mapping$1, Destination as Destination$1 } from '@walkeros/core';
|
|
2
|
+
import { DestinationServer, sendServer } from '@walkeros/server-core';
|
|
3
|
+
|
|
4
|
+
interface Settings {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
pixelId: string;
|
|
7
|
+
action_source?: ActionSource;
|
|
8
|
+
doNotHash?: string[];
|
|
9
|
+
test_mode?: boolean;
|
|
10
|
+
url?: string;
|
|
11
|
+
user_data?: Mapping$1.Map;
|
|
12
|
+
}
|
|
13
|
+
type InitSettings = Partial<Settings>;
|
|
14
|
+
interface Mapping {
|
|
15
|
+
}
|
|
16
|
+
interface Env extends DestinationServer.Env {
|
|
17
|
+
sendServer?: typeof sendServer;
|
|
18
|
+
}
|
|
19
|
+
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
20
|
+
interface Destination extends DestinationServer.Destination<Types> {
|
|
21
|
+
init: DestinationServer.InitFn<Types>;
|
|
22
|
+
}
|
|
23
|
+
type Config = {
|
|
24
|
+
settings: Settings;
|
|
25
|
+
} & DestinationServer.Config<Types>;
|
|
26
|
+
type InitFn = DestinationServer.InitFn<Types>;
|
|
27
|
+
type PushFn = DestinationServer.PushFn<Types>;
|
|
28
|
+
type PartialConfig = DestinationServer.PartialConfig<Types>;
|
|
29
|
+
type PushEvents = DestinationServer.PushEvents<Mapping>;
|
|
30
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
31
|
+
type Rules = Mapping$1.Rules<Rule>;
|
|
32
|
+
type ActionSource = 'WEBSITE' | 'APP' | 'PHYSICAL_STORE';
|
|
33
|
+
type TrackingType = 'PageVisit' | 'ViewContent' | 'Search' | 'AddToCart' | 'AddToWishlist' | 'Purchase' | 'Lead' | 'SignUp' | 'Custom';
|
|
34
|
+
interface EventType {
|
|
35
|
+
tracking_type: TrackingType;
|
|
36
|
+
custom_event_name?: string;
|
|
37
|
+
}
|
|
38
|
+
interface Product {
|
|
39
|
+
id: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
category: string;
|
|
42
|
+
}
|
|
43
|
+
interface EventMetadata {
|
|
44
|
+
conversion_id?: string;
|
|
45
|
+
item_count?: number;
|
|
46
|
+
currency?: string;
|
|
47
|
+
value?: number;
|
|
48
|
+
value_decimal?: number;
|
|
49
|
+
products?: Product[];
|
|
50
|
+
units_sold?: number;
|
|
51
|
+
country_code?: string;
|
|
52
|
+
}
|
|
53
|
+
interface ScreenDimensions {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
}
|
|
57
|
+
interface DataProcessingOptions {
|
|
58
|
+
modes: string[];
|
|
59
|
+
country?: string;
|
|
60
|
+
region?: string;
|
|
61
|
+
}
|
|
62
|
+
interface UserData {
|
|
63
|
+
email?: string;
|
|
64
|
+
external_id?: string;
|
|
65
|
+
ip_address?: string;
|
|
66
|
+
user_agent?: string;
|
|
67
|
+
idfa?: string;
|
|
68
|
+
aaid?: string;
|
|
69
|
+
uuid?: string;
|
|
70
|
+
opt_out?: boolean;
|
|
71
|
+
screen_dimensions?: ScreenDimensions;
|
|
72
|
+
data_processing_options?: DataProcessingOptions;
|
|
73
|
+
}
|
|
74
|
+
interface ConversionEvent {
|
|
75
|
+
click_id?: string;
|
|
76
|
+
event_at: string;
|
|
77
|
+
event_at_ms?: number;
|
|
78
|
+
event_type: EventType;
|
|
79
|
+
event_metadata?: EventMetadata;
|
|
80
|
+
user: UserData;
|
|
81
|
+
}
|
|
82
|
+
interface RequestBody {
|
|
83
|
+
test_mode?: boolean;
|
|
84
|
+
data: {
|
|
85
|
+
events: ConversionEvent[];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
interface ResponseBody {
|
|
89
|
+
success?: boolean;
|
|
90
|
+
message?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type index_ActionSource = ActionSource;
|
|
94
|
+
type index_Config = Config;
|
|
95
|
+
type index_ConversionEvent = ConversionEvent;
|
|
96
|
+
type index_DataProcessingOptions = DataProcessingOptions;
|
|
97
|
+
type index_Destination = Destination;
|
|
98
|
+
type index_Env = Env;
|
|
99
|
+
type index_EventMetadata = EventMetadata;
|
|
100
|
+
type index_EventType = EventType;
|
|
101
|
+
type index_InitFn = InitFn;
|
|
102
|
+
type index_InitSettings = InitSettings;
|
|
103
|
+
type index_Mapping = Mapping;
|
|
104
|
+
type index_PartialConfig = PartialConfig;
|
|
105
|
+
type index_Product = Product;
|
|
106
|
+
type index_PushEvents = PushEvents;
|
|
107
|
+
type index_PushFn = PushFn;
|
|
108
|
+
type index_RequestBody = RequestBody;
|
|
109
|
+
type index_ResponseBody = ResponseBody;
|
|
110
|
+
type index_Rule = Rule;
|
|
111
|
+
type index_Rules = Rules;
|
|
112
|
+
type index_ScreenDimensions = ScreenDimensions;
|
|
113
|
+
type index_Settings = Settings;
|
|
114
|
+
type index_TrackingType = TrackingType;
|
|
115
|
+
type index_Types = Types;
|
|
116
|
+
type index_UserData = UserData;
|
|
117
|
+
declare namespace index {
|
|
118
|
+
export type { index_ActionSource as ActionSource, index_Config as Config, index_ConversionEvent as ConversionEvent, index_DataProcessingOptions as DataProcessingOptions, index_Destination as Destination, index_Env as Env, index_EventMetadata as EventMetadata, index_EventType as EventType, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_Product as Product, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RequestBody as RequestBody, index_ResponseBody as ResponseBody, index_Rule as Rule, index_Rules as Rules, index_ScreenDimensions as ScreenDimensions, index_Settings as Settings, index_TrackingType as TrackingType, index_Types as Types, index_UserData as UserData };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare const destinationReddit: Destination;
|
|
122
|
+
|
|
123
|
+
export { index as DestinationReddit, destinationReddit as default, destinationReddit };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,index_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{DestinationReddit:()=>types_exports,default:()=>index_default,destinationReddit:()=>destinationReddit}),module.exports=(mod=index_exports,((to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to})(__defProp({},"__esModule",{value:!0}),mod));var import_core2=require("@walkeros/core"),import_server_core2=require("@walkeros/server-core"),import_core=require("@walkeros/core"),import_server_core=require("@walkeros/server-core"),keysToHash=["email","external_id","ip_address","user_agent","idfa","aaid"];function shouldBeHashed(key,doNotHash=[]){return keysToHash.includes(key)&&!doNotHash.includes(key)}async function processValue(value,shouldHash){return shouldHash?(0,import_core.isArray)(value)?Promise.all(value.map(item=>(0,import_server_core.getHashServer)(String(item)))):(0,import_server_core.getHashServer)(String(value)):value}var STANDARD_TRACKING_TYPES=new Set(["PageVisit","ViewContent","Search","AddToCart","AddToWishlist","Purchase","Lead","SignUp","Custom"]);function buildEventType(name){return function(name){return STANDARD_TRACKING_TYPES.has(name)}(name)&&"Custom"!==name?{tracking_type:name}:{tracking_type:"Custom",custom_event_name:name}}var push=async function(event,{config:config,data:data,env:env,logger:logger}){var _a;const{accessToken:accessToken,pixelId:pixelId,action_source:_action_source,doNotHash:doNotHash,test_mode:test_mode,url:url="https://ads-api.reddit.com/api/v2.0/conversions/events/",user_data:user_data}=config.settings,eventData=(0,import_core2.isObject)(data)?data:{},configData=config.data?await(0,import_core2.getMappingValue)(event,config.data):{},userDataCustom=user_data?await(0,import_core2.getMappingValue)(event,{map:user_data}):{},userData={...(0,import_core2.isObject)(configData)&&(0,import_core2.isObject)(configData.user)?configData.user:{},...(0,import_core2.isObject)(userDataCustom)?userDataCustom:{},...(0,import_core2.isObject)(eventData.user)?eventData.user:{}},{user:_u,event_metadata:eventMetadata,click_id:eventClickId,...restEventData}=eventData,timestampMs=event.timestamp||Date.now(),serverEvent={event_at:new Date(timestampMs).toISOString(),event_at_ms:timestampMs,event_type:buildEventType(event.name),...restEventData,user:userData},metadataFromMapping=(0,import_core2.isObject)(eventMetadata)?eventMetadata:{};serverEvent.event_metadata={conversion_id:event.id,...metadataFromMapping},"string"==typeof eventClickId&&(serverEvent.click_id=eventClickId);const hashedServerEvent=await async function(value,doNotHash=[]){if(!(0,import_core.isObject)(value))return value;const isUser="user"in value,target=isUser?value.user:value,result=(await Promise.all(Object.entries(target).map(async([k,v])=>[k,await processValue(v,isUser&&shouldBeHashed(k,doNotHash))]))).reduce((acc,[k,v])=>((0,import_core.isString)(k)&&(acc[k]=v),acc),{});return isUser?{...value,user:result}:result}(serverEvent,doNotHash),body={...test_mode?{test_mode:!0}:{},data:{events:[hashedServerEvent]}},endpoint=`${url}${pixelId}`;logger.debug("Calling Reddit API",{endpoint:endpoint,method:"POST",trackingType:serverEvent.event_type.tracking_type,eventId:null==(_a=serverEvent.event_metadata)?void 0:_a.conversion_id});const sendServerFn=(null==env?void 0:env.sendServer)||import_server_core2.sendServer,result=await sendServerFn(endpoint,JSON.stringify(body),{headers:{Authorization:`Bearer ${accessToken}`}});logger.debug("Reddit API response",{ok:!(0,import_core2.isObject)(result)||result.ok}),(0,import_core2.isObject)(result)&&!1===result.ok&&logger.throw(`Reddit API error: ${JSON.stringify(result)}`)},types_exports={},destinationReddit={type:"reddit",config:{},async init({config:partialConfig,logger:logger}){const config=function(partialConfig={},logger){const settings=partialConfig.settings||{},{accessToken:accessToken,pixelId:pixelId}=settings;accessToken||logger.throw("Config settings accessToken missing"),pixelId||logger.throw("Config settings pixelId missing");const settingsConfig={...settings,accessToken:accessToken,pixelId:pixelId};return{...partialConfig,settings:settingsConfig}}(partialConfig,logger);return config},push:async(event,context)=>await push(event,context)},index_default=destinationReddit;//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/push.ts","../src/hash.ts","../src/types/index.ts"],"sourcesContent":["import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationReddit from './types';\n\nexport const destinationReddit: Destination = {\n type: 'reddit',\n\n config: {},\n\n async init({ config: partialConfig, logger }) {\n const config = getConfig(partialConfig, logger);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n};\n\nexport default destinationReddit;\n","import type { Config, Settings, PartialConfig } from './types';\nimport type { Logger } from '@walkeros/core';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n logger: Logger.Instance,\n): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { accessToken, pixelId } = settings;\n\n if (!accessToken) logger.throw('Config settings accessToken missing');\n if (!pixelId) logger.throw('Config settings pixelId missing');\n\n const settingsConfig: Settings = {\n ...settings,\n accessToken,\n pixelId,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type {\n ConversionEvent,\n EventType,\n PushFn,\n RequestBody,\n TrackingType,\n UserData,\n} from './types';\nimport { getMappingValue, isObject } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport { hashEvent } from './hash';\n\nconst STANDARD_TRACKING_TYPES: ReadonlySet<TrackingType> =\n new Set<TrackingType>([\n 'PageVisit',\n 'ViewContent',\n 'Search',\n 'AddToCart',\n 'AddToWishlist',\n 'Purchase',\n 'Lead',\n 'SignUp',\n 'Custom',\n ]);\n\nfunction isStandardTrackingType(name: string): name is TrackingType {\n return STANDARD_TRACKING_TYPES.has(name as TrackingType);\n}\n\nfunction buildEventType(name: string): EventType {\n if (isStandardTrackingType(name) && name !== 'Custom') {\n return { tracking_type: name };\n }\n return { tracking_type: 'Custom', custom_event_name: name };\n}\n\nexport const push: PushFn = async function (\n event,\n { config, data, env, logger },\n) {\n const {\n accessToken,\n pixelId,\n action_source: _action_source,\n doNotHash,\n test_mode,\n url = 'https://ads-api.reddit.com/api/v2.0/conversions/events/',\n user_data,\n } = config.settings!;\n\n const eventData = isObject(data) ? data : {};\n const configData = config.data\n ? await getMappingValue(event, config.data)\n : {};\n const userDataCustom = user_data\n ? await getMappingValue(event, { map: user_data })\n : {};\n\n // Merge user data from config.data, settings.user_data, and event mapping\n const userData: UserData = {\n ...(isObject(configData) && isObject(configData.user)\n ? configData.user\n : {}),\n ...(isObject(userDataCustom) ? userDataCustom : {}),\n ...(isObject(eventData.user) ? eventData.user : {}),\n };\n\n const {\n user: _u,\n event_metadata: eventMetadata,\n click_id: eventClickId,\n ...restEventData\n } = eventData;\n\n const timestampMs = event.timestamp || Date.now();\n\n const serverEvent: ConversionEvent = {\n event_at: new Date(timestampMs).toISOString(),\n event_at_ms: timestampMs,\n event_type: buildEventType(event.name),\n ...restEventData,\n user: userData,\n };\n\n // Merge event_metadata with auto-populated conversion_id (event.id for dedup)\n const metadataFromMapping = isObject(eventMetadata) ? eventMetadata : {};\n serverEvent.event_metadata = {\n conversion_id: event.id,\n ...metadataFromMapping,\n };\n\n if (typeof eventClickId === 'string') {\n serverEvent.click_id = eventClickId;\n }\n\n const hashedServerEvent = await hashEvent(serverEvent, doNotHash);\n\n const body: RequestBody = {\n ...(test_mode ? { test_mode: true } : {}),\n data: { events: [hashedServerEvent] },\n };\n\n const endpoint = `${url}${pixelId}`;\n\n logger.debug('Calling Reddit API', {\n endpoint,\n method: 'POST',\n trackingType: serverEvent.event_type.tracking_type,\n eventId: serverEvent.event_metadata?.conversion_id,\n });\n\n const sendServerFn = env?.sendServer || sendServer;\n const result = await sendServerFn(endpoint, JSON.stringify(body), {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n\n logger.debug('Reddit API response', {\n ok: isObject(result) ? result.ok : true,\n });\n\n if (isObject(result) && result.ok === false) {\n logger.throw(`Reddit API error: ${JSON.stringify(result)}`);\n }\n};\n","import { WalkerOS } from '@walkeros/core';\nimport { isArray, isObject, isString } from '@walkeros/core';\nimport { getHashServer } from '@walkeros/server-core';\n\nconst keysToHash = [\n 'email',\n 'external_id',\n 'ip_address',\n 'user_agent',\n 'idfa',\n 'aaid',\n];\n\nfunction shouldBeHashed(key: string, doNotHash: string[] = []): boolean {\n return keysToHash.includes(key) && !doNotHash.includes(key);\n}\n\ntype HashableValue = WalkerOS.AnyObject | unknown | unknown[];\n\nasync function processValue(\n value: unknown,\n shouldHash: boolean,\n): Promise<unknown> {\n if (!shouldHash) return value;\n if (isArray(value)) {\n return Promise.all(value.map((item) => getHashServer(String(item))));\n }\n return getHashServer(String(value));\n}\n\nexport async function hashEvent<T extends HashableValue>(\n value: T,\n doNotHash: string[] = [],\n): Promise<T> {\n if (!isObject(value)) return value;\n\n const isUser = 'user' in value;\n const target = (isUser ? value.user : value) as WalkerOS.AnyObject;\n\n const entries = await Promise.all(\n Object.entries(target).map(async ([k, v]) => [\n k,\n await processValue(v, isUser && shouldBeHashed(k, doNotHash)),\n ]),\n );\n\n const result = entries.reduce((acc, [k, v]) => {\n if (isString(k)) acc[k] = v;\n return acc;\n }, {} as WalkerOS.AnyObject);\n\n return isUser ? { ...value, user: result } : (result as T);\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer, sendServer } from '@walkeros/server-core';\n\nexport interface Settings {\n accessToken: string;\n pixelId: string;\n action_source?: ActionSource;\n doNotHash?: string[];\n test_mode?: boolean;\n url?: string;\n user_data?: WalkerOSMapping.Map;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n// Reddit Conversions API types\n// https://ads-api.reddit.com/docs/v2/#tag/Conversions-API\n\nexport type ActionSource = 'WEBSITE' | 'APP' | 'PHYSICAL_STORE';\n\nexport type TrackingType =\n | 'PageVisit'\n | 'ViewContent'\n | 'Search'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'Purchase'\n | 'Lead'\n | 'SignUp'\n | 'Custom';\n\nexport interface EventType {\n tracking_type: TrackingType;\n custom_event_name?: string;\n}\n\nexport interface Product {\n id: string;\n name?: string;\n category: string;\n}\n\nexport interface EventMetadata {\n conversion_id?: string;\n item_count?: number;\n currency?: string;\n value?: number;\n value_decimal?: number;\n products?: Product[];\n units_sold?: number;\n country_code?: string;\n}\n\nexport interface ScreenDimensions {\n width: number;\n height: number;\n}\n\nexport interface DataProcessingOptions {\n modes: string[];\n country?: string;\n region?: string;\n}\n\nexport interface UserData {\n // Hashable fields (SHA-256)\n email?: string;\n external_id?: string;\n ip_address?: string;\n user_agent?: string;\n idfa?: string;\n aaid?: string;\n\n // Pass-through fields (not hashed)\n uuid?: string;\n opt_out?: boolean;\n screen_dimensions?: ScreenDimensions;\n data_processing_options?: DataProcessingOptions;\n}\n\nexport interface ConversionEvent {\n click_id?: string;\n event_at: string;\n event_at_ms?: number;\n event_type: EventType;\n event_metadata?: EventMetadata;\n user: UserData;\n}\n\nexport interface RequestBody {\n test_mode?: boolean;\n data: {\n events: ConversionEvent[];\n };\n}\n\nexport interface ResponseBody {\n success?: boolean;\n message?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,UACd,gBAA+B,CAAC,GAChC,QACQ;AACR,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,QAAQ,CAAC;AAAA,EAET,MAAM,KAAK,EAAE,QAAQ,eAAe,OAAO,GAAG;AAC5C,UAAM,SAAS,UAAU,eAAe,MAAM;AAC9C,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,SAAS;AACzB,WAAO,MAAM,KAAK,OAAO,OAAO;AAAA,EAClC;AACF;AAEA,IAAO,gBAAQ;","names":["import_core","import_server_core"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getMappingValue,isObject as isObject2}from"@walkeros/core";import{sendServer}from"@walkeros/server-core";import{isArray,isObject,isString}from"@walkeros/core";import{getHashServer}from"@walkeros/server-core";var keysToHash=["email","external_id","ip_address","user_agent","idfa","aaid"];function shouldBeHashed(key,doNotHash=[]){return keysToHash.includes(key)&&!doNotHash.includes(key)}async function processValue(value,shouldHash){return shouldHash?isArray(value)?Promise.all(value.map(item=>getHashServer(String(item)))):getHashServer(String(value)):value}var STANDARD_TRACKING_TYPES=new Set(["PageVisit","ViewContent","Search","AddToCart","AddToWishlist","Purchase","Lead","SignUp","Custom"]);function buildEventType(name){return function(name){return STANDARD_TRACKING_TYPES.has(name)}(name)&&"Custom"!==name?{tracking_type:name}:{tracking_type:"Custom",custom_event_name:name}}var push=async function(event,{config:config,data:data,env:env,logger:logger}){var _a;const{accessToken:accessToken,pixelId:pixelId,action_source:_action_source,doNotHash:doNotHash,test_mode:test_mode,url:url="https://ads-api.reddit.com/api/v2.0/conversions/events/",user_data:user_data}=config.settings,eventData=isObject2(data)?data:{},configData=config.data?await getMappingValue(event,config.data):{},userDataCustom=user_data?await getMappingValue(event,{map:user_data}):{},userData={...isObject2(configData)&&isObject2(configData.user)?configData.user:{},...isObject2(userDataCustom)?userDataCustom:{},...isObject2(eventData.user)?eventData.user:{}},{user:_u,event_metadata:eventMetadata,click_id:eventClickId,...restEventData}=eventData,timestampMs=event.timestamp||Date.now(),serverEvent={event_at:new Date(timestampMs).toISOString(),event_at_ms:timestampMs,event_type:buildEventType(event.name),...restEventData,user:userData},metadataFromMapping=isObject2(eventMetadata)?eventMetadata:{};serverEvent.event_metadata={conversion_id:event.id,...metadataFromMapping},"string"==typeof eventClickId&&(serverEvent.click_id=eventClickId);const hashedServerEvent=await async function(value,doNotHash=[]){if(!isObject(value))return value;const isUser="user"in value,target=isUser?value.user:value,result=(await Promise.all(Object.entries(target).map(async([k,v])=>[k,await processValue(v,isUser&&shouldBeHashed(k,doNotHash))]))).reduce((acc,[k,v])=>(isString(k)&&(acc[k]=v),acc),{});return isUser?{...value,user:result}:result}(serverEvent,doNotHash),body={...test_mode?{test_mode:!0}:{},data:{events:[hashedServerEvent]}},endpoint=`${url}${pixelId}`;logger.debug("Calling Reddit API",{endpoint:endpoint,method:"POST",trackingType:serverEvent.event_type.tracking_type,eventId:null==(_a=serverEvent.event_metadata)?void 0:_a.conversion_id});const sendServerFn=(null==env?void 0:env.sendServer)||sendServer,result=await sendServerFn(endpoint,JSON.stringify(body),{headers:{Authorization:`Bearer ${accessToken}`}});logger.debug("Reddit API response",{ok:!isObject2(result)||result.ok}),isObject2(result)&&!1===result.ok&&logger.throw(`Reddit API error: ${JSON.stringify(result)}`)},types_exports={},destinationReddit={type:"reddit",config:{},async init({config:partialConfig,logger:logger}){const config=function(partialConfig={},logger){const settings=partialConfig.settings||{},{accessToken:accessToken,pixelId:pixelId}=settings;accessToken||logger.throw("Config settings accessToken missing"),pixelId||logger.throw("Config settings pixelId missing");const settingsConfig={...settings,accessToken:accessToken,pixelId:pixelId};return{...partialConfig,settings:settingsConfig}}(partialConfig,logger);return config},push:async(event,context)=>await push(event,context)},index_default=destinationReddit;export{types_exports as DestinationReddit,index_default as default,destinationReddit};//# sourceMappingURL=index.mjs.map
|