@junobuild/analytics 0.0.17 → 0.0.19
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/declarations/orbiter/orbiter.did.d.ts +42 -0
- package/declarations/orbiter/orbiter.factory.did.js +48 -0
- package/declarations/orbiter/orbiter.factory.did.mjs +192 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/declarations/orbiter/orbiter.did.d.ts +42 -0
- package/dist/declarations/orbiter/orbiter.factory.did.js +48 -0
- package/dist/declarations/orbiter/orbiter.factory.did.mjs +192 -0
- package/dist/node/index.mjs.map +1 -1
- package/dist/workers/analytics.worker.js +14 -14
- package/dist/workers/analytics.worker.js.map +3 -3
- package/package.json +1 -1
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
import type {ActorMethod} from '@dfinity/agent';
|
|
2
|
+
import type {IDL} from '@dfinity/candid';
|
|
2
3
|
import type {Principal} from '@dfinity/principal';
|
|
3
4
|
|
|
4
5
|
export interface AnalyticKey {
|
|
5
6
|
key: string;
|
|
6
7
|
collected_at: bigint;
|
|
7
8
|
}
|
|
9
|
+
export interface AnalyticsBrowsersPageViews {
|
|
10
|
+
safari: number;
|
|
11
|
+
opera: number;
|
|
12
|
+
others: number;
|
|
13
|
+
firefox: number;
|
|
14
|
+
chrome: number;
|
|
15
|
+
}
|
|
16
|
+
export interface AnalyticsClientsPageViews {
|
|
17
|
+
browsers: AnalyticsBrowsersPageViews;
|
|
18
|
+
devices: AnalyticsDevicesPageViews;
|
|
19
|
+
}
|
|
20
|
+
export interface AnalyticsDevicesPageViews {
|
|
21
|
+
desktop: number;
|
|
22
|
+
others: number;
|
|
23
|
+
mobile: number;
|
|
24
|
+
}
|
|
25
|
+
export interface AnalyticsMetricsPageViews {
|
|
26
|
+
bounce_rate: number;
|
|
27
|
+
average_page_views_per_session: number;
|
|
28
|
+
daily_total_page_views: Array<[CalendarDate, number]>;
|
|
29
|
+
total_page_views: number;
|
|
30
|
+
unique_page_views: bigint;
|
|
31
|
+
unique_sessions: bigint;
|
|
32
|
+
}
|
|
33
|
+
export interface AnalyticsTop10PageViews {
|
|
34
|
+
referrers: Array<[string, number]>;
|
|
35
|
+
pages: Array<[string, number]>;
|
|
36
|
+
}
|
|
37
|
+
export interface AnalyticsTrackEvents {
|
|
38
|
+
total: Array<[string, number]>;
|
|
39
|
+
}
|
|
40
|
+
export interface CalendarDate {
|
|
41
|
+
day: number;
|
|
42
|
+
month: number;
|
|
43
|
+
year: number;
|
|
44
|
+
}
|
|
8
45
|
export interface Controller {
|
|
9
46
|
updated_at: bigint;
|
|
10
47
|
metadata: Array<[string, string]>;
|
|
@@ -101,7 +138,11 @@ export interface _SERVICE {
|
|
|
101
138
|
del_satellite_config: ActorMethod<[Principal, DelSatelliteConfig], undefined>;
|
|
102
139
|
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
103
140
|
get_page_views: ActorMethod<[GetAnalytics], Array<[AnalyticKey, PageView]>>;
|
|
141
|
+
get_page_views_analytics_clients: ActorMethod<[GetAnalytics], AnalyticsClientsPageViews>;
|
|
142
|
+
get_page_views_analytics_metrics: ActorMethod<[GetAnalytics], AnalyticsMetricsPageViews>;
|
|
143
|
+
get_page_views_analytics_top_10: ActorMethod<[GetAnalytics], AnalyticsTop10PageViews>;
|
|
104
144
|
get_track_events: ActorMethod<[GetAnalytics], Array<[AnalyticKey, TrackEvent]>>;
|
|
145
|
+
get_track_events_analytics: ActorMethod<[GetAnalytics], AnalyticsTrackEvents>;
|
|
105
146
|
list_controllers: ActorMethod<[], Array<[Principal, Controller]>>;
|
|
106
147
|
list_satellite_configs: ActorMethod<[], Array<[Principal, OrbiterSatelliteConfig]>>;
|
|
107
148
|
memory_size: ActorMethod<[], MemorySize>;
|
|
@@ -116,3 +157,4 @@ export interface _SERVICE {
|
|
|
116
157
|
set_track_events: ActorMethod<[Array<[AnalyticKey, SetTrackEvent]>], Result_1>;
|
|
117
158
|
version: ActorMethod<[], string>;
|
|
118
159
|
}
|
|
160
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
@@ -44,6 +44,39 @@ export const idlFactory = ({IDL}) => {
|
|
|
44
44
|
device: PageViewDevice,
|
|
45
45
|
user_agent: IDL.Opt(IDL.Text)
|
|
46
46
|
});
|
|
47
|
+
const AnalyticsBrowsersPageViews = IDL.Record({
|
|
48
|
+
safari: IDL.Float64,
|
|
49
|
+
opera: IDL.Float64,
|
|
50
|
+
others: IDL.Float64,
|
|
51
|
+
firefox: IDL.Float64,
|
|
52
|
+
chrome: IDL.Float64
|
|
53
|
+
});
|
|
54
|
+
const AnalyticsDevicesPageViews = IDL.Record({
|
|
55
|
+
desktop: IDL.Float64,
|
|
56
|
+
others: IDL.Float64,
|
|
57
|
+
mobile: IDL.Float64
|
|
58
|
+
});
|
|
59
|
+
const AnalyticsClientsPageViews = IDL.Record({
|
|
60
|
+
browsers: AnalyticsBrowsersPageViews,
|
|
61
|
+
devices: AnalyticsDevicesPageViews
|
|
62
|
+
});
|
|
63
|
+
const CalendarDate = IDL.Record({
|
|
64
|
+
day: IDL.Nat8,
|
|
65
|
+
month: IDL.Nat8,
|
|
66
|
+
year: IDL.Int32
|
|
67
|
+
});
|
|
68
|
+
const AnalyticsMetricsPageViews = IDL.Record({
|
|
69
|
+
bounce_rate: IDL.Float64,
|
|
70
|
+
average_page_views_per_session: IDL.Float64,
|
|
71
|
+
daily_total_page_views: IDL.Vec(IDL.Tuple(CalendarDate, IDL.Nat32)),
|
|
72
|
+
total_page_views: IDL.Nat32,
|
|
73
|
+
unique_page_views: IDL.Nat64,
|
|
74
|
+
unique_sessions: IDL.Nat64
|
|
75
|
+
});
|
|
76
|
+
const AnalyticsTop10PageViews = IDL.Record({
|
|
77
|
+
referrers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32)),
|
|
78
|
+
pages: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32))
|
|
79
|
+
});
|
|
47
80
|
const TrackEvent = IDL.Record({
|
|
48
81
|
updated_at: IDL.Nat64,
|
|
49
82
|
session_id: IDL.Text,
|
|
@@ -52,6 +85,9 @@ export const idlFactory = ({IDL}) => {
|
|
|
52
85
|
created_at: IDL.Nat64,
|
|
53
86
|
satellite_id: IDL.Principal
|
|
54
87
|
});
|
|
88
|
+
const AnalyticsTrackEvents = IDL.Record({
|
|
89
|
+
total: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32))
|
|
90
|
+
});
|
|
55
91
|
const OrbiterSatelliteConfig = IDL.Record({
|
|
56
92
|
updated_at: IDL.Nat64,
|
|
57
93
|
created_at: IDL.Nat64,
|
|
@@ -109,11 +145,23 @@ export const idlFactory = ({IDL}) => {
|
|
|
109
145
|
[IDL.Vec(IDL.Tuple(AnalyticKey, PageView))],
|
|
110
146
|
['query']
|
|
111
147
|
),
|
|
148
|
+
get_page_views_analytics_clients: IDL.Func(
|
|
149
|
+
[GetAnalytics],
|
|
150
|
+
[AnalyticsClientsPageViews],
|
|
151
|
+
['query']
|
|
152
|
+
),
|
|
153
|
+
get_page_views_analytics_metrics: IDL.Func(
|
|
154
|
+
[GetAnalytics],
|
|
155
|
+
[AnalyticsMetricsPageViews],
|
|
156
|
+
['query']
|
|
157
|
+
),
|
|
158
|
+
get_page_views_analytics_top_10: IDL.Func([GetAnalytics], [AnalyticsTop10PageViews], ['query']),
|
|
112
159
|
get_track_events: IDL.Func(
|
|
113
160
|
[GetAnalytics],
|
|
114
161
|
[IDL.Vec(IDL.Tuple(AnalyticKey, TrackEvent))],
|
|
115
162
|
['query']
|
|
116
163
|
),
|
|
164
|
+
get_track_events_analytics: IDL.Func([GetAnalytics], [AnalyticsTrackEvents], ['query']),
|
|
117
165
|
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
118
166
|
list_satellite_configs: IDL.Func(
|
|
119
167
|
[],
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
export const idlFactory = ({IDL}) => {
|
|
3
|
+
const DeleteControllersArgs = IDL.Record({
|
|
4
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
5
|
+
});
|
|
6
|
+
const ControllerScope = IDL.Variant({
|
|
7
|
+
Write: IDL.Null,
|
|
8
|
+
Admin: IDL.Null
|
|
9
|
+
});
|
|
10
|
+
const Controller = IDL.Record({
|
|
11
|
+
updated_at: IDL.Nat64,
|
|
12
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
13
|
+
created_at: IDL.Nat64,
|
|
14
|
+
scope: ControllerScope,
|
|
15
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
16
|
+
});
|
|
17
|
+
const DelSatelliteConfig = IDL.Record({updated_at: IDL.Opt(IDL.Nat64)});
|
|
18
|
+
const DepositCyclesArgs = IDL.Record({
|
|
19
|
+
cycles: IDL.Nat,
|
|
20
|
+
destination_id: IDL.Principal
|
|
21
|
+
});
|
|
22
|
+
const GetAnalytics = IDL.Record({
|
|
23
|
+
to: IDL.Opt(IDL.Nat64),
|
|
24
|
+
from: IDL.Opt(IDL.Nat64),
|
|
25
|
+
satellite_id: IDL.Opt(IDL.Principal)
|
|
26
|
+
});
|
|
27
|
+
const AnalyticKey = IDL.Record({
|
|
28
|
+
key: IDL.Text,
|
|
29
|
+
collected_at: IDL.Nat64
|
|
30
|
+
});
|
|
31
|
+
const PageViewDevice = IDL.Record({
|
|
32
|
+
inner_height: IDL.Nat16,
|
|
33
|
+
inner_width: IDL.Nat16
|
|
34
|
+
});
|
|
35
|
+
const PageView = IDL.Record({
|
|
36
|
+
title: IDL.Text,
|
|
37
|
+
updated_at: IDL.Nat64,
|
|
38
|
+
referrer: IDL.Opt(IDL.Text),
|
|
39
|
+
time_zone: IDL.Text,
|
|
40
|
+
session_id: IDL.Text,
|
|
41
|
+
href: IDL.Text,
|
|
42
|
+
created_at: IDL.Nat64,
|
|
43
|
+
satellite_id: IDL.Principal,
|
|
44
|
+
device: PageViewDevice,
|
|
45
|
+
user_agent: IDL.Opt(IDL.Text)
|
|
46
|
+
});
|
|
47
|
+
const AnalyticsBrowsersPageViews = IDL.Record({
|
|
48
|
+
safari: IDL.Float64,
|
|
49
|
+
opera: IDL.Float64,
|
|
50
|
+
others: IDL.Float64,
|
|
51
|
+
firefox: IDL.Float64,
|
|
52
|
+
chrome: IDL.Float64
|
|
53
|
+
});
|
|
54
|
+
const AnalyticsDevicesPageViews = IDL.Record({
|
|
55
|
+
desktop: IDL.Float64,
|
|
56
|
+
others: IDL.Float64,
|
|
57
|
+
mobile: IDL.Float64
|
|
58
|
+
});
|
|
59
|
+
const AnalyticsClientsPageViews = IDL.Record({
|
|
60
|
+
browsers: AnalyticsBrowsersPageViews,
|
|
61
|
+
devices: AnalyticsDevicesPageViews
|
|
62
|
+
});
|
|
63
|
+
const CalendarDate = IDL.Record({
|
|
64
|
+
day: IDL.Nat8,
|
|
65
|
+
month: IDL.Nat8,
|
|
66
|
+
year: IDL.Int32
|
|
67
|
+
});
|
|
68
|
+
const AnalyticsMetricsPageViews = IDL.Record({
|
|
69
|
+
bounce_rate: IDL.Float64,
|
|
70
|
+
average_page_views_per_session: IDL.Float64,
|
|
71
|
+
daily_total_page_views: IDL.Vec(IDL.Tuple(CalendarDate, IDL.Nat32)),
|
|
72
|
+
total_page_views: IDL.Nat32,
|
|
73
|
+
unique_page_views: IDL.Nat64,
|
|
74
|
+
unique_sessions: IDL.Nat64
|
|
75
|
+
});
|
|
76
|
+
const AnalyticsTop10PageViews = IDL.Record({
|
|
77
|
+
referrers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32)),
|
|
78
|
+
pages: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32))
|
|
79
|
+
});
|
|
80
|
+
const TrackEvent = IDL.Record({
|
|
81
|
+
updated_at: IDL.Nat64,
|
|
82
|
+
session_id: IDL.Text,
|
|
83
|
+
metadata: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))),
|
|
84
|
+
name: IDL.Text,
|
|
85
|
+
created_at: IDL.Nat64,
|
|
86
|
+
satellite_id: IDL.Principal
|
|
87
|
+
});
|
|
88
|
+
const AnalyticsTrackEvents = IDL.Record({
|
|
89
|
+
total: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32))
|
|
90
|
+
});
|
|
91
|
+
const OrbiterSatelliteConfig = IDL.Record({
|
|
92
|
+
updated_at: IDL.Nat64,
|
|
93
|
+
created_at: IDL.Nat64,
|
|
94
|
+
enabled: IDL.Bool
|
|
95
|
+
});
|
|
96
|
+
const MemorySize = IDL.Record({stable: IDL.Nat64, heap: IDL.Nat64});
|
|
97
|
+
const SetController = IDL.Record({
|
|
98
|
+
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
|
|
99
|
+
scope: ControllerScope,
|
|
100
|
+
expires_at: IDL.Opt(IDL.Nat64)
|
|
101
|
+
});
|
|
102
|
+
const SetControllersArgs = IDL.Record({
|
|
103
|
+
controller: SetController,
|
|
104
|
+
controllers: IDL.Vec(IDL.Principal)
|
|
105
|
+
});
|
|
106
|
+
const SetPageView = IDL.Record({
|
|
107
|
+
title: IDL.Text,
|
|
108
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
109
|
+
referrer: IDL.Opt(IDL.Text),
|
|
110
|
+
time_zone: IDL.Text,
|
|
111
|
+
session_id: IDL.Text,
|
|
112
|
+
href: IDL.Text,
|
|
113
|
+
satellite_id: IDL.Principal,
|
|
114
|
+
device: PageViewDevice,
|
|
115
|
+
user_agent: IDL.Opt(IDL.Text)
|
|
116
|
+
});
|
|
117
|
+
const Result = IDL.Variant({Ok: PageView, Err: IDL.Text});
|
|
118
|
+
const Result_1 = IDL.Variant({
|
|
119
|
+
Ok: IDL.Null,
|
|
120
|
+
Err: IDL.Vec(IDL.Tuple(AnalyticKey, IDL.Text))
|
|
121
|
+
});
|
|
122
|
+
const SetSatelliteConfig = IDL.Record({
|
|
123
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
124
|
+
enabled: IDL.Bool
|
|
125
|
+
});
|
|
126
|
+
const SetTrackEvent = IDL.Record({
|
|
127
|
+
updated_at: IDL.Opt(IDL.Nat64),
|
|
128
|
+
session_id: IDL.Text,
|
|
129
|
+
metadata: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))),
|
|
130
|
+
name: IDL.Text,
|
|
131
|
+
satellite_id: IDL.Principal,
|
|
132
|
+
user_agent: IDL.Opt(IDL.Text)
|
|
133
|
+
});
|
|
134
|
+
const Result_2 = IDL.Variant({Ok: TrackEvent, Err: IDL.Text});
|
|
135
|
+
return IDL.Service({
|
|
136
|
+
del_controllers: IDL.Func(
|
|
137
|
+
[DeleteControllersArgs],
|
|
138
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, Controller))],
|
|
139
|
+
[]
|
|
140
|
+
),
|
|
141
|
+
del_satellite_config: IDL.Func([IDL.Principal, DelSatelliteConfig], [], []),
|
|
142
|
+
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
143
|
+
get_page_views: IDL.Func(
|
|
144
|
+
[GetAnalytics],
|
|
145
|
+
[IDL.Vec(IDL.Tuple(AnalyticKey, PageView))],
|
|
146
|
+
['query']
|
|
147
|
+
),
|
|
148
|
+
get_page_views_analytics_clients: IDL.Func(
|
|
149
|
+
[GetAnalytics],
|
|
150
|
+
[AnalyticsClientsPageViews],
|
|
151
|
+
['query']
|
|
152
|
+
),
|
|
153
|
+
get_page_views_analytics_metrics: IDL.Func(
|
|
154
|
+
[GetAnalytics],
|
|
155
|
+
[AnalyticsMetricsPageViews],
|
|
156
|
+
['query']
|
|
157
|
+
),
|
|
158
|
+
get_page_views_analytics_top_10: IDL.Func([GetAnalytics], [AnalyticsTop10PageViews], ['query']),
|
|
159
|
+
get_track_events: IDL.Func(
|
|
160
|
+
[GetAnalytics],
|
|
161
|
+
[IDL.Vec(IDL.Tuple(AnalyticKey, TrackEvent))],
|
|
162
|
+
['query']
|
|
163
|
+
),
|
|
164
|
+
get_track_events_analytics: IDL.Func([GetAnalytics], [AnalyticsTrackEvents], ['query']),
|
|
165
|
+
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
166
|
+
list_satellite_configs: IDL.Func(
|
|
167
|
+
[],
|
|
168
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, OrbiterSatelliteConfig))],
|
|
169
|
+
['query']
|
|
170
|
+
),
|
|
171
|
+
memory_size: IDL.Func([], [MemorySize], ['query']),
|
|
172
|
+
set_controllers: IDL.Func(
|
|
173
|
+
[SetControllersArgs],
|
|
174
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, Controller))],
|
|
175
|
+
[]
|
|
176
|
+
),
|
|
177
|
+
set_page_view: IDL.Func([AnalyticKey, SetPageView], [Result], []),
|
|
178
|
+
set_page_views: IDL.Func([IDL.Vec(IDL.Tuple(AnalyticKey, SetPageView))], [Result_1], []),
|
|
179
|
+
set_satellite_configs: IDL.Func(
|
|
180
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, SetSatelliteConfig))],
|
|
181
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, OrbiterSatelliteConfig))],
|
|
182
|
+
[]
|
|
183
|
+
),
|
|
184
|
+
set_track_event: IDL.Func([AnalyticKey, SetTrackEvent], [Result_2], []),
|
|
185
|
+
set_track_events: IDL.Func([IDL.Vec(IDL.Tuple(AnalyticKey, SetTrackEvent))], [Result_1], []),
|
|
186
|
+
version: IDL.Func([], [IDL.Text], ['query'])
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
// @ts-ignore
|
|
190
|
+
export const init = ({IDL}) => {
|
|
191
|
+
return [];
|
|
192
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../node_modules/@dfinity/principal/src/utils/base32.ts", "../../../../node_modules/@dfinity/principal/src/utils/getCrc.ts", "../../../utils/src/utils/debounce.utils.ts", "../../../utils/src/utils/json.utils.ts", "../../../utils/src/utils/null.utils.ts", "../../../utils/src/utils/did.utils.ts", "../../../utils/src/utils/env.utils.ts", "../../../../node_modules/nanoid/index.browser.js", "../../src/utils/date.utils.ts", "../../src/utils/analytics.utils.ts", "../../src/services/analytics.services.ts", "../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';\n\n// Build a lookup table for decoding.\nconst lookupTable: Record<string, number> = Object.create(null);\nfor (let i = 0; i < alphabet.length; i++) {\n lookupTable[alphabet[i]] = i;\n}\n\n// Add aliases for rfc4648.\nlookupTable['0'] = lookupTable.o;\nlookupTable['1'] = lookupTable.i;\n\n/**\n * @param input The input array to encode.\n * @returns A Base32 string encoding the input.\n */\nexport function encode(input: Uint8Array): string {\n // How many bits will we skip from the first byte.\n let skip = 0;\n // 5 high bits, carry from one byte to the next.\n let bits = 0;\n\n // The output string in base32.\n let output = '';\n\n function encodeByte(byte: number) {\n if (skip < 0) {\n // we have a carry from the previous byte\n bits |= byte >> -skip;\n } else {\n // no carry\n bits = (byte << skip) & 248;\n }\n\n if (skip > 3) {\n // Not enough data to produce a character, get us another one\n skip -= 8;\n return 1;\n }\n\n if (skip < 4) {\n // produce a character\n output += alphabet[bits >> 3];\n skip += 5;\n }\n\n return 0;\n }\n\n for (let i = 0; i < input.length; ) {\n i += encodeByte(input[i]);\n }\n\n return output + (skip < 0 ? alphabet[bits >> 3] : '');\n}\n\n/**\n * @param input The base32 encoded string to decode.\n */\nexport function decode(input: string): Uint8Array {\n // how many bits we have from the previous character.\n let skip = 0;\n // current byte we're producing.\n let byte = 0;\n\n const output = new Uint8Array(((input.length * 4) / 3) | 0);\n let o = 0;\n\n function decodeChar(char: string) {\n // Consume a character from the stream, store\n // the output in this.output. As before, better\n // to use update().\n let val = lookupTable[char.toLowerCase()];\n if (val === undefined) {\n throw new Error(`Invalid character: ${JSON.stringify(char)}`);\n }\n\n // move to the high bits\n val <<= 3;\n byte |= val >>> skip;\n skip += 5;\n\n if (skip >= 8) {\n // We have enough bytes to produce an output\n output[o++] = byte;\n skip -= 8;\n\n if (skip > 0) {\n byte = (val << (5 - skip)) & 255;\n } else {\n byte = 0;\n }\n }\n }\n\n for (const c of input) {\n decodeChar(c);\n }\n\n return output.slice(0, o);\n}\n", "// This file is translated to JavaScript from\n// https://lxp32.github.io/docs/a-simple-example-crc32-calculation/\nconst lookUpTable: Uint32Array = new Uint32Array([\n 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n]);\n\n/**\n * Calculate the CRC32 of an ArrayBufferLike.\n * @param buf The BufferLike to calculate the CRC32 of.\n */\nexport function getCrc32(buf: ArrayBufferLike): number {\n const b = new Uint8Array(buf);\n let crc = -1;\n\n for (let i = 0; i < b.length; i++) {\n const byte = b[i];\n const t = (byte ^ crc) & 0xff;\n crc = lookUpTable[t] ^ (crc >>> 8);\n }\n\n return (crc ^ -1) >>> 0;\n}\n", "/* eslint-disable-next-line @typescript-eslint/ban-types */\nexport const debounce = (func: Function, timeout?: number) => {\n let timer: NodeJS.Timer | undefined;\n\n return (...args: unknown[]) => {\n const next = () => func(...args);\n\n if (timer) {\n clearTimeout(timer);\n }\n\n timer = setTimeout(next, timeout !== undefined && timeout > 0 ? timeout : 300);\n };\n};\n", "import {Principal} from '@dfinity/principal';\nimport {nonNullish} from './null.utils';\n\nconst JSON_KEY_BIGINT = '__bigint__';\nconst JSON_KEY_PRINCIPAL = '__principal__';\nconst JSON_KEY_UINT8ARRAY = '__uint8array__';\n\n/**\n * A parser that interprets revived BigInt, Principal, and Uint8Array when constructing JavaScript values or objects.\n */\nexport const jsonReplacer = (_key: string, value: unknown): unknown => {\n if (typeof value === 'bigint') {\n return {[JSON_KEY_BIGINT]: `${value}`};\n }\n\n if (nonNullish(value) && value instanceof Principal) {\n return {[JSON_KEY_PRINCIPAL]: value.toText()};\n }\n\n if (nonNullish(value) && value instanceof Uint8Array) {\n return {[JSON_KEY_UINT8ARRAY]: Array.from(value)};\n }\n\n return value;\n};\n\n/**\n * A function that alters the behavior of the stringification process for BigInt, Principal and Uint8Array.\n */\nexport const jsonReviver = (_key: string, value: unknown): unknown => {\n const mapValue = <T>(key: string): T => (value as Record<string, T>)[key];\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_BIGINT in value) {\n return BigInt(mapValue(JSON_KEY_BIGINT));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_PRINCIPAL in value) {\n return Principal.fromText(mapValue(JSON_KEY_PRINCIPAL));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_UINT8ARRAY in value) {\n return Uint8Array.from(mapValue(JSON_KEY_UINT8ARRAY));\n }\n\n return value;\n};\n", "/** Is null or undefined */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/** Not null and not undefined */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (isNullish(value)) {\n throw new NullishError(message);\n }\n};\n", "import {jsonReplacer, jsonReviver} from './json.utils';\nimport {nonNullish} from './null.utils';\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return nonNullish(value) ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob: Blob = new Blob([data instanceof Uint8Array ? data : new Uint8Array(data)], {\n type: 'application/json; charset=utf-8'\n });\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "export const isBrowser = () => typeof window !== `undefined`;\n", "export { urlAlphabet } from './url-alphabet/index.js'\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nexport let nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\n", "export const nowInBigIntNanoSeconds = (): bigint => BigInt(Date.now()) * BigInt(1e6);\n", "import {toNullable} from '@junobuild/utils';\nimport {nowInBigIntNanoSeconds} from './date.utils';\n\nexport const timestamp = (): {collected_at: bigint; updated_at: [] | [bigint]} => ({\n collected_at: nowInBigIntNanoSeconds(),\n updated_at: []\n});\n\nexport const userAgent = (): {user_agent: [] | [string]} => {\n const {userAgent} = navigator;\n return {user_agent: toNullable(userAgent)};\n};\n", "import {assertNonNullish, isBrowser, nonNullish, toNullable} from '@junobuild/utils';\nimport {nanoid} from 'nanoid';\nimport type {Environment, EnvironmentWorker} from '../types/env';\nimport type {IdbPageView} from '../types/idb';\nimport type {PostMessageInitEnvData} from '../types/post-message';\nimport type {TrackEvent} from '../types/track';\nimport {timestamp, userAgent} from '../utils/analytics.utils';\n\nconst initSessionId = (): string | undefined => {\n // I faced this issue when I used the library in Docusaurus which does not implement the crypto API when server-side rendering.\n // https://github.com/ai/nanoid/issues?q=crypto+not+defined\n if (typeof crypto === 'undefined') {\n return undefined;\n }\n\n return nanoid();\n};\n\nconst sessionId = initSessionId();\n\nlet worker: Worker | undefined;\n\nexport const initWorker = (env: Environment): {cleanup: () => void} => {\n const {path}: EnvironmentWorker = env.worker ?? {};\n const workerUrl = path === undefined ? './workers/analytics.worker.js' : path;\n\n worker = new Worker(workerUrl);\n\n const consoleWarn = () =>\n console.warn('Unable to connect to the analytics web worker. Have you deployed it?');\n\n worker?.addEventListener('error', consoleWarn, false);\n\n initWorkerEnvironment(env);\n\n return {\n cleanup() {\n worker?.removeEventListener('error', consoleWarn, false);\n }\n };\n};\n\nexport const initTrackPageViews = (): {cleanup: () => void} => {\n const trackPages = async () => await trackPageView();\n\n let pushStateProxy: typeof history.pushState | null = new Proxy(history.pushState, {\n apply: async (\n target,\n thisArg,\n argArray: [data: unknown, unused: string, url?: string | URL | null | undefined]\n ) => {\n target.apply(thisArg, argArray);\n await trackPages();\n }\n });\n\n history.pushState = pushStateProxy;\n\n addEventListener('popstate', trackPages, {passive: true});\n\n return {\n cleanup() {\n pushStateProxy = null;\n removeEventListener('popstate', trackPages, false);\n }\n };\n};\n\nconst WORKER_UNDEFINED_MSG =\n 'Analytics worker not initialized. Did you call `initOrbiter`?' as const;\nconst SESSION_ID_UNDEFINED_MSG = 'No session ID initialized.' as const;\n\nexport const setPageView = async () => {\n if (!isBrowser()) {\n return;\n }\n\n assertNonNullish(sessionId, SESSION_ID_UNDEFINED_MSG);\n\n const {\n title,\n location: {href},\n referrer\n } = document;\n const {innerWidth, innerHeight} = window;\n const {timeZone} = Intl.DateTimeFormat().resolvedOptions();\n\n const data: IdbPageView = {\n title,\n href,\n referrer: toNullable(nonNullish(referrer) && referrer !== '' ? referrer : undefined),\n device: {\n inner_width: innerWidth,\n inner_height: innerHeight\n },\n time_zone: timeZone,\n session_id: sessionId as string,\n ...userAgent(),\n ...timestamp()\n };\n\n const idb = await import('./idb.services');\n await idb.setPageView({\n key: nanoid(),\n view: data\n });\n};\n\nexport const trackPageView = async () => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n await setPageView();\n\n worker?.postMessage({msg: 'junoTrackPageView'});\n};\n\nexport const trackEvent = async (data: TrackEvent) => {\n if (!isBrowser()) {\n return;\n }\n\n assertNonNullish(sessionId, SESSION_ID_UNDEFINED_MSG);\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n const idb = await import('./idb.services');\n await idb.setTrackEvent({\n key: nanoid(),\n track: {...data, session_id: sessionId as string, ...userAgent(), ...timestamp()}\n });\n\n worker?.postMessage({msg: 'junoTrackEvent'});\n};\n\nexport const initWorkerEnvironment = (env: PostMessageInitEnvData) => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n worker?.postMessage({msg: 'junoInitEnvironment', data: env});\n};\n\nexport const startTracking = () => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n worker?.postMessage({msg: 'junoStartTrackTimer'});\n};\n\nexport const stopTracking = () => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n worker?.postMessage({msg: 'junoStopTracker'});\n};\n", "import {\n initTrackPageViews,\n initWorker,\n setPageView,\n startTracking,\n stopTracking\n} from './services/analytics.services';\nimport type {Environment} from './types/env';\n\nexport {trackEvent, trackPageView} from './services/analytics.services';\nexport * from './types/env';\n\nexport const initOrbiter = async (env: Environment): Promise<() => void> => {\n // Save first page as soon as possible\n await setPageView();\n\n const {cleanup: workerCleanup} = initWorker(env);\n\n const {cleanup: pushHistoryCleanup} = initTrackPageViews();\n\n // Starting tracking will instantly sync the first page and the data from previous sessions that have not been synced yet\n startTracking();\n\n return () => {\n stopTracking();\n workerCleanup();\n pushHistoryCleanup();\n };\n};\n"],
|
|
4
|
+
"sourcesContent": ["const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';\n\n// Build a lookup table for decoding.\nconst lookupTable: Record<string, number> = Object.create(null);\nfor (let i = 0; i < alphabet.length; i++) {\n lookupTable[alphabet[i]] = i;\n}\n\n// Add aliases for rfc4648.\nlookupTable['0'] = lookupTable.o;\nlookupTable['1'] = lookupTable.i;\n\n/**\n * @param input The input array to encode.\n * @returns A Base32 string encoding the input.\n */\nexport function encode(input: Uint8Array): string {\n // How many bits will we skip from the first byte.\n let skip = 0;\n // 5 high bits, carry from one byte to the next.\n let bits = 0;\n\n // The output string in base32.\n let output = '';\n\n function encodeByte(byte: number) {\n if (skip < 0) {\n // we have a carry from the previous byte\n bits |= byte >> -skip;\n } else {\n // no carry\n bits = (byte << skip) & 248;\n }\n\n if (skip > 3) {\n // Not enough data to produce a character, get us another one\n skip -= 8;\n return 1;\n }\n\n if (skip < 4) {\n // produce a character\n output += alphabet[bits >> 3];\n skip += 5;\n }\n\n return 0;\n }\n\n for (let i = 0; i < input.length; ) {\n i += encodeByte(input[i]);\n }\n\n return output + (skip < 0 ? alphabet[bits >> 3] : '');\n}\n\n/**\n * @param input The base32 encoded string to decode.\n */\nexport function decode(input: string): Uint8Array {\n // how many bits we have from the previous character.\n let skip = 0;\n // current byte we're producing.\n let byte = 0;\n\n const output = new Uint8Array(((input.length * 4) / 3) | 0);\n let o = 0;\n\n function decodeChar(char: string) {\n // Consume a character from the stream, store\n // the output in this.output. As before, better\n // to use update().\n let val = lookupTable[char.toLowerCase()];\n if (val === undefined) {\n throw new Error(`Invalid character: ${JSON.stringify(char)}`);\n }\n\n // move to the high bits\n val <<= 3;\n byte |= val >>> skip;\n skip += 5;\n\n if (skip >= 8) {\n // We have enough bytes to produce an output\n output[o++] = byte;\n skip -= 8;\n\n if (skip > 0) {\n byte = (val << (5 - skip)) & 255;\n } else {\n byte = 0;\n }\n }\n }\n\n for (const c of input) {\n decodeChar(c);\n }\n\n return output.slice(0, o);\n}\n", "// This file is translated to JavaScript from\n// https://lxp32.github.io/docs/a-simple-example-crc32-calculation/\nconst lookUpTable: Uint32Array = new Uint32Array([\n 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n]);\n\n/**\n * Calculate the CRC32 of an ArrayBufferLike.\n * @param buf The BufferLike to calculate the CRC32 of.\n */\nexport function getCrc32(buf: ArrayBufferLike): number {\n const b = new Uint8Array(buf);\n let crc = -1;\n\n for (let i = 0; i < b.length; i++) {\n const byte = b[i];\n const t = (byte ^ crc) & 0xff;\n crc = lookUpTable[t] ^ (crc >>> 8);\n }\n\n return (crc ^ -1) >>> 0;\n}\n", "/* eslint-disable-next-line @typescript-eslint/ban-types */\nexport const debounce = (func: Function, timeout?: number) => {\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: unknown[]) => {\n const next = () => func(...args);\n\n if (timer) {\n clearTimeout(timer);\n }\n\n timer = setTimeout(next, timeout !== undefined && timeout > 0 ? timeout : 300);\n };\n};\n", "import {Principal} from '@dfinity/principal';\nimport {nonNullish} from './null.utils';\n\nconst JSON_KEY_BIGINT = '__bigint__';\nconst JSON_KEY_PRINCIPAL = '__principal__';\nconst JSON_KEY_UINT8ARRAY = '__uint8array__';\n\n/**\n * A parser that interprets revived BigInt, Principal, and Uint8Array when constructing JavaScript values or objects.\n */\nexport const jsonReplacer = (_key: string, value: unknown): unknown => {\n if (typeof value === 'bigint') {\n return {[JSON_KEY_BIGINT]: `${value}`};\n }\n\n if (nonNullish(value) && value instanceof Principal) {\n return {[JSON_KEY_PRINCIPAL]: value.toText()};\n }\n\n if (nonNullish(value) && value instanceof Uint8Array) {\n return {[JSON_KEY_UINT8ARRAY]: Array.from(value)};\n }\n\n return value;\n};\n\n/**\n * A function that alters the behavior of the stringification process for BigInt, Principal and Uint8Array.\n */\nexport const jsonReviver = (_key: string, value: unknown): unknown => {\n const mapValue = <T>(key: string): T => (value as Record<string, T>)[key];\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_BIGINT in value) {\n return BigInt(mapValue(JSON_KEY_BIGINT));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_PRINCIPAL in value) {\n return Principal.fromText(mapValue(JSON_KEY_PRINCIPAL));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_UINT8ARRAY in value) {\n return Uint8Array.from(mapValue(JSON_KEY_UINT8ARRAY));\n }\n\n return value;\n};\n", "/** Is null or undefined */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/** Not null and not undefined */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (isNullish(value)) {\n throw new NullishError(message);\n }\n};\n", "import {jsonReplacer, jsonReviver} from './json.utils';\nimport {nonNullish} from './null.utils';\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return nonNullish(value) ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob: Blob = new Blob([data instanceof Uint8Array ? data : new Uint8Array(data)], {\n type: 'application/json; charset=utf-8'\n });\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "export const isBrowser = () => typeof window !== `undefined`;\n", "export { urlAlphabet } from './url-alphabet/index.js'\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nexport let nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\n", "export const nowInBigIntNanoSeconds = (): bigint => BigInt(Date.now()) * BigInt(1e6);\n", "import {toNullable} from '@junobuild/utils';\nimport {nowInBigIntNanoSeconds} from './date.utils';\n\nexport const timestamp = (): {collected_at: bigint; updated_at: [] | [bigint]} => ({\n collected_at: nowInBigIntNanoSeconds(),\n updated_at: []\n});\n\nexport const userAgent = (): {user_agent: [] | [string]} => {\n const {userAgent} = navigator;\n return {user_agent: toNullable(userAgent)};\n};\n", "import {assertNonNullish, isBrowser, nonNullish, toNullable} from '@junobuild/utils';\nimport {nanoid} from 'nanoid';\nimport type {Environment, EnvironmentWorker} from '../types/env';\nimport type {IdbPageView} from '../types/idb';\nimport type {PostMessageInitEnvData} from '../types/post-message';\nimport type {TrackEvent} from '../types/track';\nimport {timestamp, userAgent} from '../utils/analytics.utils';\n\nconst initSessionId = (): string | undefined => {\n // I faced this issue when I used the library in Docusaurus which does not implement the crypto API when server-side rendering.\n // https://github.com/ai/nanoid/issues?q=crypto+not+defined\n if (typeof crypto === 'undefined') {\n return undefined;\n }\n\n return nanoid();\n};\n\nconst sessionId = initSessionId();\n\nlet worker: Worker | undefined;\n\nexport const initWorker = (env: Environment): {cleanup: () => void} => {\n const {path}: EnvironmentWorker = env.worker ?? {};\n const workerUrl = path === undefined ? './workers/analytics.worker.js' : path;\n\n worker = new Worker(workerUrl);\n\n const consoleWarn = () =>\n console.warn('Unable to connect to the analytics web worker. Have you deployed it?');\n\n worker?.addEventListener('error', consoleWarn, false);\n\n initWorkerEnvironment(env);\n\n return {\n cleanup() {\n worker?.removeEventListener('error', consoleWarn, false);\n }\n };\n};\n\nexport const initTrackPageViews = (): {cleanup: () => void} => {\n const trackPages = async () => await trackPageView();\n\n let pushStateProxy: typeof history.pushState | null = new Proxy(history.pushState, {\n apply: async (\n target,\n thisArg,\n argArray: [data: unknown, unused: string, url?: string | URL | null | undefined]\n ) => {\n target.apply(thisArg, argArray);\n await trackPages();\n }\n });\n\n history.pushState = pushStateProxy;\n\n addEventListener('popstate', trackPages, {passive: true});\n\n return {\n cleanup() {\n pushStateProxy = null;\n removeEventListener('popstate', trackPages, false);\n }\n };\n};\n\nconst WORKER_UNDEFINED_MSG =\n 'Analytics worker not initialized. Did you call `initOrbiter`?' as const;\nconst SESSION_ID_UNDEFINED_MSG = 'No session ID initialized.' as const;\n\nexport const setPageView = async () => {\n if (!isBrowser()) {\n return;\n }\n\n assertNonNullish(sessionId, SESSION_ID_UNDEFINED_MSG);\n\n const {\n title,\n location: {href},\n referrer\n } = document;\n const {innerWidth, innerHeight} = window;\n const {timeZone} = Intl.DateTimeFormat().resolvedOptions();\n\n const data: IdbPageView = {\n title,\n href,\n referrer: toNullable(nonNullish(referrer) && referrer !== '' ? referrer : undefined),\n device: {\n inner_width: innerWidth,\n inner_height: innerHeight\n },\n time_zone: timeZone,\n session_id: sessionId as string,\n ...userAgent(),\n ...timestamp()\n };\n\n const idb = await import('./idb.services');\n await idb.setPageView({\n key: nanoid(),\n view: data\n });\n};\n\nexport const trackPageView = async () => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n await setPageView();\n\n worker?.postMessage({msg: 'junoTrackPageView'});\n};\n\nexport const trackEvent = async (data: TrackEvent) => {\n if (!isBrowser()) {\n return;\n }\n\n assertNonNullish(sessionId, SESSION_ID_UNDEFINED_MSG);\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n const idb = await import('./idb.services');\n await idb.setTrackEvent({\n key: nanoid(),\n track: {...data, session_id: sessionId as string, ...userAgent(), ...timestamp()}\n });\n\n worker?.postMessage({msg: 'junoTrackEvent'});\n};\n\nexport const initWorkerEnvironment = (env: PostMessageInitEnvData) => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n worker?.postMessage({msg: 'junoInitEnvironment', data: env});\n};\n\nexport const startTracking = () => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n worker?.postMessage({msg: 'junoStartTrackTimer'});\n};\n\nexport const stopTracking = () => {\n assertNonNullish(worker, WORKER_UNDEFINED_MSG);\n\n worker?.postMessage({msg: 'junoStopTracker'});\n};\n", "import {\n initTrackPageViews,\n initWorker,\n setPageView,\n startTracking,\n stopTracking\n} from './services/analytics.services';\nimport type {Environment} from './types/env';\n\nexport {trackEvent, trackPageView} from './services/analytics.services';\nexport * from './types/env';\n\nexport const initOrbiter = async (env: Environment): Promise<() => void> => {\n // Save first page as soon as possible\n await setPageView();\n\n const {cleanup: workerCleanup} = initWorker(env);\n\n const {cleanup: pushHistoryCleanup} = initTrackPageViews();\n\n // Starting tracking will instantly sync the first page and the data from previous sessions that have not been synced yet\n startTracking();\n\n return () => {\n stopTracking();\n workerCleanup();\n pushHistoryCleanup();\n };\n};\n"],
|
|
5
5
|
"mappings": "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",
|
|
6
6
|
"names": ["alphabet", "lookupTable", "i", "lookUpTable", "isNullish", "argument", "nonNullish", "NullishError", "assertNonNullish", "value", "message", "toNullable", "value", "nonNullish", "isBrowser", "nanoid", "size", "id", "byte", "nowInBigIntNanoSeconds", "timestamp", "nowInBigIntNanoSeconds", "userAgent", "g", "initSessionId", "nanoid", "sessionId", "worker", "initWorker", "env", "path", "workerUrl", "consoleWarn", "initWorkerEnvironment", "initTrackPageViews", "trackPages", "trackPageView", "pushStateProxy", "target", "thisArg", "argArray", "WORKER_UNDEFINED_MSG", "SESSION_ID_UNDEFINED_MSG", "setPageView", "h", "x", "title", "href", "referrer", "innerWidth", "innerHeight", "timeZone", "data", "g", "t", "userAgent", "timestamp", "trackEvent", "startTracking", "stopTracking", "initOrbiter", "env", "setPageView", "workerCleanup", "initWorker", "pushHistoryCleanup", "initTrackPageViews", "startTracking", "stopTracking"]
|
|
7
7
|
}
|
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
import type {ActorMethod} from '@dfinity/agent';
|
|
2
|
+
import type {IDL} from '@dfinity/candid';
|
|
2
3
|
import type {Principal} from '@dfinity/principal';
|
|
3
4
|
|
|
4
5
|
export interface AnalyticKey {
|
|
5
6
|
key: string;
|
|
6
7
|
collected_at: bigint;
|
|
7
8
|
}
|
|
9
|
+
export interface AnalyticsBrowsersPageViews {
|
|
10
|
+
safari: number;
|
|
11
|
+
opera: number;
|
|
12
|
+
others: number;
|
|
13
|
+
firefox: number;
|
|
14
|
+
chrome: number;
|
|
15
|
+
}
|
|
16
|
+
export interface AnalyticsClientsPageViews {
|
|
17
|
+
browsers: AnalyticsBrowsersPageViews;
|
|
18
|
+
devices: AnalyticsDevicesPageViews;
|
|
19
|
+
}
|
|
20
|
+
export interface AnalyticsDevicesPageViews {
|
|
21
|
+
desktop: number;
|
|
22
|
+
others: number;
|
|
23
|
+
mobile: number;
|
|
24
|
+
}
|
|
25
|
+
export interface AnalyticsMetricsPageViews {
|
|
26
|
+
bounce_rate: number;
|
|
27
|
+
average_page_views_per_session: number;
|
|
28
|
+
daily_total_page_views: Array<[CalendarDate, number]>;
|
|
29
|
+
total_page_views: number;
|
|
30
|
+
unique_page_views: bigint;
|
|
31
|
+
unique_sessions: bigint;
|
|
32
|
+
}
|
|
33
|
+
export interface AnalyticsTop10PageViews {
|
|
34
|
+
referrers: Array<[string, number]>;
|
|
35
|
+
pages: Array<[string, number]>;
|
|
36
|
+
}
|
|
37
|
+
export interface AnalyticsTrackEvents {
|
|
38
|
+
total: Array<[string, number]>;
|
|
39
|
+
}
|
|
40
|
+
export interface CalendarDate {
|
|
41
|
+
day: number;
|
|
42
|
+
month: number;
|
|
43
|
+
year: number;
|
|
44
|
+
}
|
|
8
45
|
export interface Controller {
|
|
9
46
|
updated_at: bigint;
|
|
10
47
|
metadata: Array<[string, string]>;
|
|
@@ -101,7 +138,11 @@ export interface _SERVICE {
|
|
|
101
138
|
del_satellite_config: ActorMethod<[Principal, DelSatelliteConfig], undefined>;
|
|
102
139
|
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
103
140
|
get_page_views: ActorMethod<[GetAnalytics], Array<[AnalyticKey, PageView]>>;
|
|
141
|
+
get_page_views_analytics_clients: ActorMethod<[GetAnalytics], AnalyticsClientsPageViews>;
|
|
142
|
+
get_page_views_analytics_metrics: ActorMethod<[GetAnalytics], AnalyticsMetricsPageViews>;
|
|
143
|
+
get_page_views_analytics_top_10: ActorMethod<[GetAnalytics], AnalyticsTop10PageViews>;
|
|
104
144
|
get_track_events: ActorMethod<[GetAnalytics], Array<[AnalyticKey, TrackEvent]>>;
|
|
145
|
+
get_track_events_analytics: ActorMethod<[GetAnalytics], AnalyticsTrackEvents>;
|
|
105
146
|
list_controllers: ActorMethod<[], Array<[Principal, Controller]>>;
|
|
106
147
|
list_satellite_configs: ActorMethod<[], Array<[Principal, OrbiterSatelliteConfig]>>;
|
|
107
148
|
memory_size: ActorMethod<[], MemorySize>;
|
|
@@ -116,3 +157,4 @@ export interface _SERVICE {
|
|
|
116
157
|
set_track_events: ActorMethod<[Array<[AnalyticKey, SetTrackEvent]>], Result_1>;
|
|
117
158
|
version: ActorMethod<[], string>;
|
|
118
159
|
}
|
|
160
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
@@ -44,6 +44,39 @@ export const idlFactory = ({IDL}) => {
|
|
|
44
44
|
device: PageViewDevice,
|
|
45
45
|
user_agent: IDL.Opt(IDL.Text)
|
|
46
46
|
});
|
|
47
|
+
const AnalyticsBrowsersPageViews = IDL.Record({
|
|
48
|
+
safari: IDL.Float64,
|
|
49
|
+
opera: IDL.Float64,
|
|
50
|
+
others: IDL.Float64,
|
|
51
|
+
firefox: IDL.Float64,
|
|
52
|
+
chrome: IDL.Float64
|
|
53
|
+
});
|
|
54
|
+
const AnalyticsDevicesPageViews = IDL.Record({
|
|
55
|
+
desktop: IDL.Float64,
|
|
56
|
+
others: IDL.Float64,
|
|
57
|
+
mobile: IDL.Float64
|
|
58
|
+
});
|
|
59
|
+
const AnalyticsClientsPageViews = IDL.Record({
|
|
60
|
+
browsers: AnalyticsBrowsersPageViews,
|
|
61
|
+
devices: AnalyticsDevicesPageViews
|
|
62
|
+
});
|
|
63
|
+
const CalendarDate = IDL.Record({
|
|
64
|
+
day: IDL.Nat8,
|
|
65
|
+
month: IDL.Nat8,
|
|
66
|
+
year: IDL.Int32
|
|
67
|
+
});
|
|
68
|
+
const AnalyticsMetricsPageViews = IDL.Record({
|
|
69
|
+
bounce_rate: IDL.Float64,
|
|
70
|
+
average_page_views_per_session: IDL.Float64,
|
|
71
|
+
daily_total_page_views: IDL.Vec(IDL.Tuple(CalendarDate, IDL.Nat32)),
|
|
72
|
+
total_page_views: IDL.Nat32,
|
|
73
|
+
unique_page_views: IDL.Nat64,
|
|
74
|
+
unique_sessions: IDL.Nat64
|
|
75
|
+
});
|
|
76
|
+
const AnalyticsTop10PageViews = IDL.Record({
|
|
77
|
+
referrers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32)),
|
|
78
|
+
pages: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32))
|
|
79
|
+
});
|
|
47
80
|
const TrackEvent = IDL.Record({
|
|
48
81
|
updated_at: IDL.Nat64,
|
|
49
82
|
session_id: IDL.Text,
|
|
@@ -52,6 +85,9 @@ export const idlFactory = ({IDL}) => {
|
|
|
52
85
|
created_at: IDL.Nat64,
|
|
53
86
|
satellite_id: IDL.Principal
|
|
54
87
|
});
|
|
88
|
+
const AnalyticsTrackEvents = IDL.Record({
|
|
89
|
+
total: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat32))
|
|
90
|
+
});
|
|
55
91
|
const OrbiterSatelliteConfig = IDL.Record({
|
|
56
92
|
updated_at: IDL.Nat64,
|
|
57
93
|
created_at: IDL.Nat64,
|
|
@@ -109,11 +145,23 @@ export const idlFactory = ({IDL}) => {
|
|
|
109
145
|
[IDL.Vec(IDL.Tuple(AnalyticKey, PageView))],
|
|
110
146
|
['query']
|
|
111
147
|
),
|
|
148
|
+
get_page_views_analytics_clients: IDL.Func(
|
|
149
|
+
[GetAnalytics],
|
|
150
|
+
[AnalyticsClientsPageViews],
|
|
151
|
+
['query']
|
|
152
|
+
),
|
|
153
|
+
get_page_views_analytics_metrics: IDL.Func(
|
|
154
|
+
[GetAnalytics],
|
|
155
|
+
[AnalyticsMetricsPageViews],
|
|
156
|
+
['query']
|
|
157
|
+
),
|
|
158
|
+
get_page_views_analytics_top_10: IDL.Func([GetAnalytics], [AnalyticsTop10PageViews], ['query']),
|
|
112
159
|
get_track_events: IDL.Func(
|
|
113
160
|
[GetAnalytics],
|
|
114
161
|
[IDL.Vec(IDL.Tuple(AnalyticKey, TrackEvent))],
|
|
115
162
|
['query']
|
|
116
163
|
),
|
|
164
|
+
get_track_events_analytics: IDL.Func([GetAnalytics], [AnalyticsTrackEvents], ['query']),
|
|
117
165
|
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
118
166
|
list_satellite_configs: IDL.Func(
|
|
119
167
|
[],
|