@stacksee/analytics 0.13.0 → 0.13.2

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.
@@ -1,829 +0,0 @@
1
- import { a as S, r as F, b as w } from "./axios-0_CwElpL.js";
2
- import { a as R } from "./_commonjsHelpers-B4e78b8K.js";
3
- function I(r, i) {
4
- for (var _ = 0; _ < i.length; _++) {
5
- const f = i[_];
6
- if (typeof f != "string" && !Array.isArray(f)) {
7
- for (const l in f)
8
- if (l !== "default" && !(l in r)) {
9
- const e = Object.getOwnPropertyDescriptor(f, l);
10
- e && Object.defineProperty(r, l, e.get ? e : {
11
- enumerable: !0,
12
- get: () => f[l]
13
- });
14
- }
15
- }
16
- }
17
- return Object.freeze(Object.defineProperty(r, Symbol.toStringTag, { value: "Module" }));
18
- }
19
- var g = {}, T = {}, A;
20
- function N() {
21
- return A || (A = 1, Object.defineProperty(T, "__esModule", { value: !0 })), T;
22
- }
23
- var v = {};
24
- const H = {}, U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
25
- __proto__: null,
26
- default: H
27
- }, Symbol.toStringTag, { value: "Module" })), j = /* @__PURE__ */ R(U);
28
- var C = {}, b;
29
- function x() {
30
- if (b) return C;
31
- b = 1;
32
- var r = C && C.__awaiter || function(l, e, d, c) {
33
- function h(u) {
34
- return u instanceof d ? u : new d(function(a) {
35
- a(u);
36
- });
37
- }
38
- return new (d || (d = Promise))(function(u, a) {
39
- function t(o) {
40
- try {
41
- n(c.next(o));
42
- } catch (p) {
43
- a(p);
44
- }
45
- }
46
- function s(o) {
47
- try {
48
- n(c.throw(o));
49
- } catch (p) {
50
- a(p);
51
- }
52
- }
53
- function n(o) {
54
- o.done ? u(o.value) : h(o.value).then(t, s);
55
- }
56
- n((c = c.apply(l, e || [])).next());
57
- });
58
- };
59
- Object.defineProperty(C, "__esModule", { value: !0 }), C.PirschCoreClient = void 0;
60
- const i = S(), _ = F();
61
- class f extends _.PirschCommon {
62
- /**
63
- * The constructor creates a new client.
64
- *
65
- * @param {object} configuration You need to pass in the **Client ID** and **Client Secret** or **Access Key** you have configured on the Pirsch dashboard.
66
- * It's also recommended to set the proper protocol for your website, else it will be set to `https` by default.
67
- * All other configuration parameters can be left to their defaults.
68
- * @param {string} configuration.baseUrl The base URL for the pirsch API
69
- * @param {number} configuration.timeout The default HTTP timeout in milliseconds
70
- * @param {string} configuration.clientId The OAuth client ID
71
- * @param {string} configuration.clientSecret The OAuth client secret
72
- * @param {string} configuration.protocol The default HTTP protocol to use for tracking
73
- *
74
- */
75
- constructor(e) {
76
- super(), this.version = "v1", this.endpoint = "api", this.accessToken = "";
77
- const { baseUrl: d = i.PIRSCH_DEFAULT_BASE_URL, timeout: c = i.PIRSCH_DEFAULT_TIMEOUT } = e;
78
- if (this.baseUrl = d, this.timeout = c, "accessToken" in e) {
79
- const { accessToken: h } = e;
80
- this.assertAccessTokenCredentials({ accessToken: h }), this.accessToken = h, this.accessMode = "access-token";
81
- } else if ("clientId" in e || "clientSecret" in e) {
82
- const { clientId: h, clientSecret: u } = e;
83
- this.assertOauthCredentials({ clientId: h, clientSecret: u }), this.clientId = h, this.clientSecret = u, this.accessMode = "oauth";
84
- } else
85
- throw new Error(`Missing credentials, please supply either '${JSON.stringify({
86
- clientId: "value",
87
- clientSecret: "value"
88
- })}' or '${JSON.stringify({
89
- accessToken: "value"
90
- })}'!`);
91
- }
92
- /**
93
- * hit sends a hit to Pirsch. Make sure you call it in all request handlers you want to track.
94
- * Also, make sure to filter out unwanted pathnames (like /favicon.ico in your root handler for example).
95
- *
96
- * @param hit all required data for the request.
97
- * @returns APIError or an empty promise, in case something went wrong
98
- */
99
- hit(e) {
100
- return r(this, void 0, void 0, function* () {
101
- return yield this.performPost(i.PirschEndpoint.HIT, e);
102
- });
103
- }
104
- /**
105
- * batchHit sends batched hits to Pirsch.
106
- *
107
- * @param hits all required data for the request.
108
- * @returns APIError or an empty promise, in case something went wrong
109
- */
110
- batchHits(e) {
111
- return r(this, void 0, void 0, function* () {
112
- return yield this.performPost(i.PirschEndpoint.HIT_BATCH, e);
113
- });
114
- }
115
- /**
116
- * event sends an event to Pirsch. Make sure you call it in all request handlers you want to track.
117
- * Also, make sure to filter out unwanted pathnames (like /favicon.ico in your root handler for example).
118
- *
119
- * @param name the name for the event
120
- * @param hit all required data for the request
121
- * @param duration optional duration for the event
122
- * @param meta optional object containing metadata (only scalar values, like strings, numbers, and booleans)
123
- * @returns APIError or an empty promise, in case something went wrong
124
- */
125
- event(e, d) {
126
- return r(this, arguments, void 0, function* (c, h, u = 0, a) {
127
- const t = Object.assign({ event_name: c, event_duration: u, event_meta: this.prepareScalarObject(a) }, h);
128
- return yield this.performPost(i.PirschEndpoint.EVENT, t);
129
- });
130
- }
131
- /**
132
- * batchEvents sends batched events to Pirsch.
133
- *
134
- * @param events all required data for the request.
135
- * @returns APIError or an empty promise, in case something went wrong
136
- */
137
- batchEvents(e) {
138
- return r(this, void 0, void 0, function* () {
139
- const d = e.map(({ name: c, hit: h, time: u, duration: a = 0, meta: t }) => Object.assign({ event_name: c, event_duration: a, event_meta: this.prepareScalarObject(t), time: u }, h));
140
- return yield this.performPost(i.PirschEndpoint.EVENT_BATCH, d);
141
- });
142
- }
143
- /**
144
- * session keeps a session alive.
145
- *
146
- * @param session all required data for the request.
147
- * @returns APIError or an empty promise, in case something went wrong
148
- */
149
- session(e) {
150
- return r(this, void 0, void 0, function* () {
151
- return yield this.performPost(i.PirschEndpoint.SESSION, e);
152
- });
153
- }
154
- /**
155
- * batchSessions keeps batched sessions alive.
156
- *
157
- * @param sessions all required data for the request.
158
- * @returns APIError or an empty promise, in case something went wrong
159
- */
160
- batchSessions(e) {
161
- return r(this, void 0, void 0, function* () {
162
- return yield this.performPost(i.PirschEndpoint.SESSION_BATCH, e);
163
- });
164
- }
165
- /**
166
- * domain returns the domain for this client.
167
- *
168
- * @returns Domain object for this client.
169
- */
170
- domain() {
171
- return r(this, void 0, void 0, function* () {
172
- var e;
173
- this.accessModeCheck("domain");
174
- const d = yield this.performGet(i.PirschEndpoint.DOMAIN), c = new _.PirschDomainNotFoundApiError();
175
- return Array.isArray(d) && d.length === 0 ? c : Array.isArray(d) ? (e = d.at(0)) !== null && e !== void 0 ? e : c : d;
176
- });
177
- }
178
- /**
179
- * sessionDuration returns the session duration grouped by day.
180
- *
181
- * @param filter used to filter the result set.
182
- */
183
- sessionDuration(e) {
184
- return r(this, void 0, void 0, function* () {
185
- return this.accessModeCheck("sessionDuration"), yield this.performFilteredGet(i.PirschEndpoint.SESSION_DURATION, e);
186
- });
187
- }
188
- /**
189
- * timeOnPage returns the time spent on pages.
190
- *
191
- * @param filter used to filter the result set.
192
- */
193
- timeOnPage(e) {
194
- return r(this, void 0, void 0, function* () {
195
- return this.accessModeCheck("timeOnPage"), yield this.performFilteredGet(i.PirschEndpoint.TIME_ON_PAGE, e);
196
- });
197
- }
198
- /**
199
- * utmSource returns the utm sources.
200
- *
201
- * @param filter used to filter the result set.
202
- */
203
- utmSource(e) {
204
- return r(this, void 0, void 0, function* () {
205
- return this.accessModeCheck("utmSource"), yield this.performFilteredGet(i.PirschEndpoint.UTM_SOURCE, e);
206
- });
207
- }
208
- /**
209
- * utmMedium returns the utm medium.
210
- *
211
- * @param filter used to filter the result set.
212
- */
213
- utmMedium(e) {
214
- return r(this, void 0, void 0, function* () {
215
- return this.accessModeCheck("utmMedium"), yield this.performFilteredGet(i.PirschEndpoint.UTM_MEDIUM, e);
216
- });
217
- }
218
- /**
219
- * utmCampaign returns the utm campaigns.
220
- *
221
- * @param filter used to filter the result set.
222
- */
223
- utmCampaign(e) {
224
- return r(this, void 0, void 0, function* () {
225
- return this.accessModeCheck("utmCampaign"), yield this.performFilteredGet(i.PirschEndpoint.UTM_CAMPAIGN, e);
226
- });
227
- }
228
- /**
229
- * utmContent returns the utm content.
230
- *
231
- * @param filter used to filter the result set.
232
- */
233
- utmContent(e) {
234
- return r(this, void 0, void 0, function* () {
235
- return this.accessModeCheck("utmContent"), yield this.performFilteredGet(i.PirschEndpoint.UTM_CONTENT, e);
236
- });
237
- }
238
- /**
239
- * utmTerm returns the utm term.
240
- *
241
- * @param filter used to filter the result set.
242
- */
243
- utmTerm(e) {
244
- return r(this, void 0, void 0, function* () {
245
- return this.accessModeCheck("utmTerm"), yield this.performFilteredGet(i.PirschEndpoint.UTM_TERM, e);
246
- });
247
- }
248
- /**
249
- * totalVisitors returns the total visitor statistics.
250
- *
251
- * @param filter used to filter the result set.
252
- */
253
- totalVisitors(e) {
254
- return r(this, void 0, void 0, function* () {
255
- return this.accessModeCheck("totalVisitors"), yield this.performFilteredGet(i.PirschEndpoint.TOTAL_VISITORS, e);
256
- });
257
- }
258
- /**
259
- * visitors returns the visitor statistics grouped by day.
260
- *
261
- * @param filter used to filter the result set.
262
- */
263
- visitors(e) {
264
- return r(this, void 0, void 0, function* () {
265
- return this.accessModeCheck("visitors"), yield this.performFilteredGet(i.PirschEndpoint.VISITORS, e);
266
- });
267
- }
268
- /**
269
- * entryPages returns the entry page statistics grouped by page.
270
- *
271
- * @param filter used to filter the result set.
272
- */
273
- entryPages(e) {
274
- return r(this, void 0, void 0, function* () {
275
- return this.accessModeCheck("entryPages"), yield this.performFilteredGet(i.PirschEndpoint.ENTRY_PAGES, e);
276
- });
277
- }
278
- /**
279
- * exitPages returns the exit page statistics grouped by page.
280
- *
281
- * @param filter used to filter the result set.
282
- */
283
- exitPages(e) {
284
- return r(this, void 0, void 0, function* () {
285
- return this.accessModeCheck("exitPages"), yield this.performFilteredGet(i.PirschEndpoint.EXIT_PAGES, e);
286
- });
287
- }
288
- /**
289
- * pages returns the page statistics grouped by page.
290
- *
291
- * @param filter used to filter the result set.
292
- */
293
- pages(e) {
294
- return r(this, void 0, void 0, function* () {
295
- return this.accessModeCheck("pages"), yield this.performFilteredGet(i.PirschEndpoint.PAGES, e);
296
- });
297
- }
298
- /**
299
- * conversionGoals returns all conversion goals.
300
- *
301
- * @param filter used to filter the result set.
302
- */
303
- conversionGoals(e) {
304
- return r(this, void 0, void 0, function* () {
305
- return this.accessModeCheck("conversionGoals"), yield this.performFilteredGet(i.PirschEndpoint.CONVERSION_GOALS, e);
306
- });
307
- }
308
- /**
309
- * events returns all events.
310
- *
311
- * @param filter used to filter the result set.
312
- */
313
- events(e) {
314
- return r(this, void 0, void 0, function* () {
315
- return this.accessModeCheck("events"), yield this.performFilteredGet(i.PirschEndpoint.EVENTS, e);
316
- });
317
- }
318
- /**
319
- * eventMetadata returns the metadata for a single event.
320
- * The event name and metadata key must be set in the filter, or otherwise no results will be returned.
321
- *
322
- * @param filter used to filter the result set.
323
- */
324
- eventMetadata(e) {
325
- return r(this, void 0, void 0, function* () {
326
- return this.accessModeCheck("eventMetadata"), yield this.performFilteredGet(i.PirschEndpoint.EVENT_METADATA, e);
327
- });
328
- }
329
- /**
330
- * listEvents returns a list of all events including metadata.
331
- *
332
- * @param filter used to filter the result set.
333
- */
334
- listEvents(e) {
335
- return r(this, void 0, void 0, function* () {
336
- return this.accessModeCheck("listEvents"), yield this.performFilteredGet(i.PirschEndpoint.LIST_EVENTS, e);
337
- });
338
- }
339
- /**
340
- * eventPages returns all pages an event has been triggered on.
341
- * The event name must be set in the filter, or otherwise no results will be returned.
342
- *
343
- * @param filter used to filter the result set.
344
- */
345
- eventPages(e) {
346
- return r(this, void 0, void 0, function* () {
347
- return this.accessModeCheck("eventPages"), yield this.performFilteredGet(i.PirschEndpoint.EVENTS_PAGES, e);
348
- });
349
- }
350
- /**
351
- * growth returns the growth rates for visitors, bounces, ...
352
- *
353
- * @param filter used to filter the result set.
354
- */
355
- growth(e) {
356
- return r(this, void 0, void 0, function* () {
357
- return this.accessModeCheck("growth"), yield this.performFilteredGet(i.PirschEndpoint.GROWTH_RATE, e);
358
- });
359
- }
360
- /**
361
- * activeVisitors returns the active visitors and what pages they're on.
362
- *
363
- * @param filter used to filter the result set.
364
- */
365
- activeVisitors(e) {
366
- return r(this, void 0, void 0, function* () {
367
- return this.accessModeCheck("activeVisitors"), yield this.performFilteredGet(i.PirschEndpoint.ACTIVE_VISITORS, e);
368
- });
369
- }
370
- /**
371
- * timeOfDay returns the number of unique visitors grouped by time of day.
372
- *
373
- * @param filter used to filter the result set.
374
- */
375
- timeOfDay(e) {
376
- return r(this, void 0, void 0, function* () {
377
- return this.accessModeCheck("timeOfDay"), yield this.performFilteredGet(i.PirschEndpoint.TIME_OF_DAY, e);
378
- });
379
- }
380
- /**
381
- * languages returns language statistics.
382
- *
383
- * @param filter used to filter the result set.
384
- */
385
- languages(e) {
386
- return r(this, void 0, void 0, function* () {
387
- return this.accessModeCheck("languages"), yield this.performFilteredGet(i.PirschEndpoint.LANGUAGE, e);
388
- });
389
- }
390
- /**
391
- * referrer returns referrer statistics.
392
- *
393
- * @param filter used to filter the result set.
394
- */
395
- referrer(e) {
396
- return r(this, void 0, void 0, function* () {
397
- return this.accessModeCheck("referrer"), yield this.performFilteredGet(i.PirschEndpoint.REFERRER, e);
398
- });
399
- }
400
- /**
401
- * os returns operating system statistics.
402
- *
403
- * @param filter used to filter the result set.
404
- */
405
- os(e) {
406
- return r(this, void 0, void 0, function* () {
407
- return this.accessModeCheck("os"), yield this.performFilteredGet(i.PirschEndpoint.OS, e);
408
- });
409
- }
410
- /**
411
- * osVersions returns operating system version statistics.
412
- *
413
- * @param filter used to filter the result set.
414
- */
415
- osVersions(e) {
416
- return r(this, void 0, void 0, function* () {
417
- return this.accessModeCheck("osVersions"), yield this.performFilteredGet(i.PirschEndpoint.OS_VERSION, e);
418
- });
419
- }
420
- /**
421
- * browser returns browser statistics.
422
- *
423
- * @param filter used to filter the result set.
424
- */
425
- browser(e) {
426
- return r(this, void 0, void 0, function* () {
427
- return this.accessModeCheck("browser"), yield this.performFilteredGet(i.PirschEndpoint.BROWSER, e);
428
- });
429
- }
430
- /**
431
- * browserVersions returns browser version statistics.
432
- *
433
- * @param filter used to filter the result set.
434
- */
435
- browserVersions(e) {
436
- return r(this, void 0, void 0, function* () {
437
- return this.accessModeCheck("browserVersions"), yield this.performFilteredGet(i.PirschEndpoint.BROWSER_VERSION, e);
438
- });
439
- }
440
- /**
441
- * country returns country statistics.
442
- *
443
- * @param filter used to filter the result set.
444
- */
445
- country(e) {
446
- return r(this, void 0, void 0, function* () {
447
- return this.accessModeCheck("country"), yield this.performFilteredGet(i.PirschEndpoint.COUNTRY, e);
448
- });
449
- }
450
- /**
451
- * region returns regional statistics.
452
- *
453
- * @param filter used to filter the result set.
454
- */
455
- region(e) {
456
- return r(this, void 0, void 0, function* () {
457
- return this.accessModeCheck("region"), yield this.performFilteredGet(i.PirschEndpoint.REGION, e);
458
- });
459
- }
460
- /**
461
- * city returns city statistics.
462
- *
463
- * @param filter used to filter the result set.
464
- */
465
- city(e) {
466
- return r(this, void 0, void 0, function* () {
467
- return this.accessModeCheck("city"), yield this.performFilteredGet(i.PirschEndpoint.CITY, e);
468
- });
469
- }
470
- /**
471
- * platform returns the platforms used by visitors.
472
- *
473
- * @param filter used to filter the result set.
474
- */
475
- platform(e) {
476
- return r(this, void 0, void 0, function* () {
477
- return this.accessModeCheck("platform"), yield this.performFilteredGet(i.PirschEndpoint.PLATFORM, e);
478
- });
479
- }
480
- /**
481
- * screen returns the screen classes used by visitors.
482
- *
483
- * @param filter used to filter the result set.
484
- */
485
- screen(e) {
486
- return r(this, void 0, void 0, function* () {
487
- return this.accessModeCheck("screen"), yield this.performFilteredGet(i.PirschEndpoint.SCREEN, e);
488
- });
489
- }
490
- /**
491
- * screen returns the screen classes used by visitors.
492
- *
493
- * @param filter used to filter the result set.
494
- */
495
- tagKeys(e) {
496
- return r(this, void 0, void 0, function* () {
497
- return this.accessModeCheck("tag_keys"), yield this.performFilteredGet(i.PirschEndpoint.TAG_KEYS, e);
498
- });
499
- }
500
- /**
501
- * screen returns the screen classes used by visitors.
502
- *
503
- * @param filter used to filter the result set.
504
- */
505
- tags(e) {
506
- return r(this, void 0, void 0, function* () {
507
- return this.accessModeCheck("tags"), yield this.performFilteredGet(i.PirschEndpoint.TAG_DETAILS, e);
508
- });
509
- }
510
- /**
511
- * keywords returns the Google keywords, rank, and CTR.
512
- *
513
- * @param filter used to filter the result set.
514
- */
515
- keywords(e) {
516
- return r(this, void 0, void 0, function* () {
517
- return this.accessModeCheck("keywords"), yield this.performFilteredGet(i.PirschEndpoint.KEYWORDS, e);
518
- });
519
- }
520
- /**
521
- * listFunnel returns a list of all funnels including step definition for given domain ID.
522
- *
523
- * @param filter used to filter the result set.
524
- */
525
- listFunnel(e) {
526
- return r(this, void 0, void 0, function* () {
527
- return this.accessModeCheck("listFunnel"), yield this.performFilteredGet(i.PirschEndpoint.LIST_FUNNEL, e);
528
- });
529
- }
530
- /**
531
- * funnel returns a list of all funnels including step definition for given domain ID.
532
- *
533
- * @param filter used to filter the result set. Then funnel_id must be set.
534
- */
535
- funnel(e) {
536
- return r(this, void 0, void 0, function* () {
537
- return this.accessModeCheck("funnel"), yield this.performFilteredGet(i.PirschEndpoint.FUNNEL, e);
538
- });
539
- }
540
- performPost(e, d) {
541
- return r(this, arguments, void 0, function* (c, h, u = !0) {
542
- try {
543
- yield this.post(this.generateUrl(c), h, {
544
- headers: {
545
- "Content-Type": "application/json",
546
- Authorization: `Bearer ${this.accessToken}`
547
- }
548
- });
549
- return;
550
- } catch (a) {
551
- const t = yield this.toApiError(a);
552
- if (this.accessMode === "oauth" && t.code === 401 && u)
553
- return yield this.refreshToken(), this.performPost(c, h, !1);
554
- throw t;
555
- }
556
- });
557
- }
558
- performGet(e) {
559
- return r(this, arguments, void 0, function* (d, c = {}, h = !0) {
560
- try {
561
- return !this.accessToken && h && (yield this.refreshToken()), yield this.get(this.generateUrl(d), {
562
- headers: {
563
- "Content-Type": "application/json",
564
- Authorization: `Bearer ${this.accessToken}`
565
- },
566
- parameters: c
567
- });
568
- } catch (u) {
569
- const a = yield this.toApiError(u);
570
- if (this.accessMode === "oauth" && a.code === 401 && h)
571
- return yield this.refreshToken(), this.performGet(d, c, !1);
572
- throw a;
573
- }
574
- });
575
- }
576
- performFilteredGet(e, d) {
577
- return r(this, void 0, void 0, function* () {
578
- return this.performGet(e, this.getFilterParams(d));
579
- });
580
- }
581
- getFilterParams(e) {
582
- const d = {
583
- id: e.id,
584
- from: e.from,
585
- to: e.to,
586
- start: e.start,
587
- scale: e.scale,
588
- tz: e.tz,
589
- path: e.path,
590
- pattern: e.pattern,
591
- entry_path: e.entry_path,
592
- exit_path: e.exit_path,
593
- event: e.event,
594
- event_meta_key: e.event_meta_key,
595
- language: e.language,
596
- country: e.country,
597
- region: e.region,
598
- city: e.city,
599
- referrer: e.referrer,
600
- referrer_name: e.referrer_name,
601
- os: e.os,
602
- browser: e.browser,
603
- platform: e.platform,
604
- screen_class: e.screen_class,
605
- utm_source: e.utm_source,
606
- utm_medium: e.utm_medium,
607
- utm_campaign: e.utm_campaign,
608
- utm_content: e.utm_content,
609
- utm_term: e.utm_term,
610
- tag: e.tag,
611
- custom_metric_key: e.custom_metric_key,
612
- custom_metric_type: e.custom_metric_type,
613
- search: e.search,
614
- offset: e.offset,
615
- limit: e.limit,
616
- sort: e.sort,
617
- direction: e.direction,
618
- include_avg_time_on_page: e.include_avg_time_on_page
619
- };
620
- if (e.event_meta)
621
- for (const [c, h] of Object.entries(e.event_meta))
622
- d[`meta_${c}`] = h;
623
- if (e.tags)
624
- for (const [c, h] of Object.entries(e.tags))
625
- d[`tag_${c}`] = h;
626
- return d;
627
- }
628
- refreshToken() {
629
- return r(this, void 0, void 0, function* () {
630
- if (this.accessMode !== "access-token")
631
- try {
632
- const e = yield this.post(this.generateUrl(i.PirschEndpoint.AUTHENTICATION), {
633
- client_id: this.clientId,
634
- client_secret: this.clientSecret
635
- });
636
- this.accessToken = e.access_token;
637
- return;
638
- } catch (e) {
639
- return this.accessToken = "", yield this.toApiError(e);
640
- }
641
- });
642
- }
643
- generateUrl(e) {
644
- return "/" + [this.endpoint, this.version, e].join("/");
645
- }
646
- accessModeCheck(e) {
647
- if (this.accessMode === "access-token")
648
- throw new _.PirschInvalidAccessModeApiError(e);
649
- }
650
- }
651
- return C.PirschCoreClient = f, C;
652
- }
653
- var k;
654
- function V() {
655
- if (k) return v;
656
- k = 1;
657
- var r = v && v.__createBinding || (Object.create ? (function(a, t, s, n) {
658
- n === void 0 && (n = s);
659
- var o = Object.getOwnPropertyDescriptor(t, s);
660
- (!o || ("get" in o ? !t.__esModule : o.writable || o.configurable)) && (o = { enumerable: !0, get: function() {
661
- return t[s];
662
- } }), Object.defineProperty(a, n, o);
663
- }) : (function(a, t, s, n) {
664
- n === void 0 && (n = s), a[n] = t[s];
665
- })), i = v && v.__setModuleDefault || (Object.create ? (function(a, t) {
666
- Object.defineProperty(a, "default", { enumerable: !0, value: t });
667
- }) : function(a, t) {
668
- a.default = t;
669
- }), _ = v && v.__importStar || /* @__PURE__ */ (function() {
670
- var a = function(t) {
671
- return a = Object.getOwnPropertyNames || function(s) {
672
- var n = [];
673
- for (var o in s) Object.prototype.hasOwnProperty.call(s, o) && (n[n.length] = o);
674
- return n;
675
- }, a(t);
676
- };
677
- return function(t) {
678
- if (t && t.__esModule) return t;
679
- var s = {};
680
- if (t != null) for (var n = a(t), o = 0; o < n.length; o++) n[o] !== "default" && r(s, t, n[o]);
681
- return i(s, t), s;
682
- };
683
- })(), f = v && v.__awaiter || function(a, t, s, n) {
684
- function o(p) {
685
- return p instanceof s ? p : new s(function(m) {
686
- m(p);
687
- });
688
- }
689
- return new (s || (s = Promise))(function(p, m) {
690
- function y(P) {
691
- try {
692
- O(n.next(P));
693
- } catch (M) {
694
- m(M);
695
- }
696
- }
697
- function E(P) {
698
- try {
699
- O(n.throw(P));
700
- } catch (M) {
701
- m(M);
702
- }
703
- }
704
- function O(P) {
705
- P.done ? p(P.value) : o(P.value).then(y, E);
706
- }
707
- O((n = n.apply(a, t || [])).next());
708
- });
709
- };
710
- Object.defineProperty(v, "__esModule", { value: !0 }), v.Client = v.Pirsch = v.PirschNodeApiClient = void 0;
711
- const l = j, e = _(/* @__PURE__ */ w()), d = x(), c = F(), h = S();
712
- class u extends d.PirschCoreClient {
713
- /**
714
- * The constructor creates a new client.
715
- *
716
- * @param {object} configuration You need to pass in the **Hostname**, **Client ID** and **Client Secret** or **Access Key** you have configured on the Pirsch dashboard.
717
- * It's also recommended to set the proper protocol for your website, else it will be set to `https` by default.
718
- * All other configuration parameters can be left to their defaults.
719
- * @param {string} configuration.baseUrl The base URL for the pirsch API
720
- * @param {number} configuration.timeout The default HTTP timeout in milliseconds
721
- * @param {string} configuration.clientId The OAuth client ID
722
- * @param {string} configuration.clientSecret The OAuth client secret
723
- * @param {string} configuration.hostname The hostname of the domain to track
724
- * @param {string} configuration.protocol The default HTTP protocol to use for tracking
725
- *
726
- */
727
- constructor(t) {
728
- super(t);
729
- const { protocol: s = h.PIRSCH_DEFAULT_PROTOCOL, hostname: n, trustedProxyHeaders: o } = t;
730
- this.hostname = n, this.protocol = s, this.trustedProxyHeaders = o, this.httpClient = e.default.create({ baseURL: this.baseUrl, timeout: this.timeout });
731
- }
732
- /**
733
- * hitFromRequest returns the required data to send a hit to Pirsch for a Node request object.
734
- *
735
- * @param request the Node request object from the http package.
736
- * @returns Hit object containing all necessary fields.
737
- */
738
- hitFromRequest(t) {
739
- var s, n, o;
740
- const p = new l.URL((s = t.url) !== null && s !== void 0 ? s : "", `${this.protocol}://${this.hostname}`), m = {
741
- url: p.toString(),
742
- ip: (n = t.socket.remoteAddress) !== null && n !== void 0 ? n : "",
743
- user_agent: (o = this.getHeader(t.headers, "user-agent")) !== null && o !== void 0 ? o : "",
744
- accept_language: this.getHeader(t.headers, "accept-language"),
745
- sec_ch_ua: this.getHeader(t.headers, "Sec-CH-UA"),
746
- sec_ch_ua_mobile: this.getHeader(t.headers, "Sec-CH-UA-Mobile"),
747
- sec_ch_ua_platform: this.getHeader(t.headers, "Sec-CH-UA-Platform"),
748
- sec_ch_ua_platform_version: this.getHeader(t.headers, "Sec-CH-UA-Platform-Version"),
749
- sec_ch_width: this.getHeader(t.headers, "Sec-CH-Width"),
750
- sec_ch_viewport_width: this.getHeader(t.headers, "Sec-CH-Viewport-Width"),
751
- referrer: this.getReferrer(t, p)
752
- };
753
- if (this.trustedProxyHeaders && this.trustedProxyHeaders.length > 0) {
754
- const y = this.trustedProxyHeaders.filter((E) => h.PIRSCH_PROXY_HEADERS.includes(E)).find((E) => typeof t.headers[E] == "string");
755
- if (y) {
756
- const E = this.getHeader(t.headers, y);
757
- E && (m.ip = E);
758
- }
759
- }
760
- return m;
761
- }
762
- getReferrer(t, s) {
763
- var n, o;
764
- const p = (o = (n = this.getHeader(t.headers, "referer")) !== null && n !== void 0 ? n : this.getHeader(t.headers, "referrer")) !== null && o !== void 0 ? o : "";
765
- if (p === "")
766
- for (const m of h.PIRSCH_REFERRER_QUERY_PARAMETERS) {
767
- const y = s.searchParams.get(m);
768
- if (y && y !== "")
769
- return y;
770
- }
771
- return p;
772
- }
773
- getHeader(t, s) {
774
- const n = t[s];
775
- return Array.isArray(n) ? n.at(0) : n;
776
- }
777
- get(t, s) {
778
- return f(this, void 0, void 0, function* () {
779
- return (yield this.httpClient.get(t, this.httpOptionsToAxiosOptions(s))).data;
780
- });
781
- }
782
- post(t, s, n) {
783
- return f(this, void 0, void 0, function* () {
784
- return (yield this.httpClient.post(t, s, this.httpOptionsToAxiosOptions(n))).data;
785
- });
786
- }
787
- toApiError(t) {
788
- return f(this, void 0, void 0, function* () {
789
- var s, n, o, p, m, y;
790
- if (t instanceof c.PirschApiError)
791
- return t;
792
- if (t instanceof e.AxiosError && t.response !== void 0) {
793
- const E = t;
794
- return new c.PirschApiError((n = (s = E.response) === null || s === void 0 ? void 0 : s.status) !== null && n !== void 0 ? n : 500, (p = (o = E.response) === null || o === void 0 ? void 0 : o.data) !== null && p !== void 0 ? p : { validation: {}, error: [] });
795
- }
796
- return typeof t == "object" && t !== null && "response" in t && typeof t.response == "object" && t.response !== null && "status" in t.response && "data" in t.response ? new c.PirschApiError((m = t.response.status) !== null && m !== void 0 ? m : 400, (y = t.response) === null || y === void 0 ? void 0 : y.data) : t instanceof Error ? new c.PirschUnknownApiError(t.message) : typeof t == "object" && t !== null && "message" in t && typeof t.message == "string" ? new c.PirschUnknownApiError(t.message) : new c.PirschUnknownApiError(JSON.stringify(t));
797
- });
798
- }
799
- httpOptionsToAxiosOptions(t) {
800
- const s = {};
801
- return t != null && t.headers && (s.headers = t.headers), t != null && t.parameters && (s.params = t.parameters), s;
802
- }
803
- }
804
- return v.PirschNodeApiClient = u, v.Pirsch = u, v.Client = u, v;
805
- }
806
- var G;
807
- function D() {
808
- return G || (G = 1, (function(r) {
809
- var i = g && g.__createBinding || (Object.create ? (function(f, l, e, d) {
810
- d === void 0 && (d = e);
811
- var c = Object.getOwnPropertyDescriptor(l, e);
812
- (!c || ("get" in c ? !l.__esModule : c.writable || c.configurable)) && (c = { enumerable: !0, get: function() {
813
- return l[e];
814
- } }), Object.defineProperty(f, d, c);
815
- }) : (function(f, l, e, d) {
816
- d === void 0 && (d = e), f[d] = l[e];
817
- })), _ = g && g.__exportStar || function(f, l) {
818
- for (var e in f) e !== "default" && !Object.prototype.hasOwnProperty.call(l, e) && i(l, f, e);
819
- };
820
- Object.defineProperty(r, "__esModule", { value: !0 }), _(N(), r), _(S(), r), _(V(), r);
821
- })(g)), g;
822
- }
823
- var L = D();
824
- const Y = /* @__PURE__ */ I({
825
- __proto__: null
826
- }, [L]);
827
- export {
828
- Y as i
829
- };