@junobuild/analytics 0.0.13 → 0.0.14-next-2023-12-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 +12 -7
- package/declarations/orbiter/orbiter.factory.did.js +8 -3
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/declarations/orbiter/orbiter.did.d.ts +12 -7
- package/dist/declarations/orbiter/orbiter.factory.did.js +8 -3
- package/dist/node/index.mjs +6 -1
- package/dist/node/index.mjs.map +4 -4
- package/dist/workers/analytics.worker.js +44 -27
- package/dist/workers/analytics.worker.js.map +4 -4
- package/package.json +3 -4
- package/dist/workers/analytics.worker.js.gz +0 -0
|
@@ -19,11 +19,20 @@ export interface DelSatelliteConfig {
|
|
|
19
19
|
export interface DeleteControllersArgs {
|
|
20
20
|
controllers: Array<Principal>;
|
|
21
21
|
}
|
|
22
|
+
export interface DepositCyclesArgs {
|
|
23
|
+
cycles: bigint;
|
|
24
|
+
destination_id: Principal;
|
|
25
|
+
}
|
|
22
26
|
export interface GetAnalytics {
|
|
23
27
|
to: [] | [bigint];
|
|
24
28
|
from: [] | [bigint];
|
|
25
29
|
satellite_id: [] | [Principal];
|
|
26
30
|
}
|
|
31
|
+
export interface OrbiterSatelliteConfig {
|
|
32
|
+
updated_at: bigint;
|
|
33
|
+
created_at: bigint;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
}
|
|
27
36
|
export interface PageView {
|
|
28
37
|
title: string;
|
|
29
38
|
updated_at: bigint;
|
|
@@ -43,11 +52,6 @@ export interface PageViewDevice {
|
|
|
43
52
|
export type Result = {Ok: PageView} | {Err: string};
|
|
44
53
|
export type Result_1 = {Ok: null} | {Err: Array<[AnalyticKey, string]>};
|
|
45
54
|
export type Result_2 = {Ok: TrackEvent} | {Err: string};
|
|
46
|
-
export interface SatelliteConfig {
|
|
47
|
-
updated_at: bigint;
|
|
48
|
-
created_at: bigint;
|
|
49
|
-
enabled: boolean;
|
|
50
|
-
}
|
|
51
55
|
export interface SetController {
|
|
52
56
|
metadata: Array<[string, string]>;
|
|
53
57
|
scope: ControllerScope;
|
|
@@ -91,16 +95,17 @@ export interface TrackEvent {
|
|
|
91
95
|
export interface _SERVICE {
|
|
92
96
|
del_controllers: ActorMethod<[DeleteControllersArgs], Array<[Principal, Controller]>>;
|
|
93
97
|
del_satellite_config: ActorMethod<[Principal, DelSatelliteConfig], undefined>;
|
|
98
|
+
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
94
99
|
get_page_views: ActorMethod<[GetAnalytics], Array<[AnalyticKey, PageView]>>;
|
|
95
100
|
get_track_events: ActorMethod<[GetAnalytics], Array<[AnalyticKey, TrackEvent]>>;
|
|
96
101
|
list_controllers: ActorMethod<[], Array<[Principal, Controller]>>;
|
|
97
|
-
list_satellite_configs: ActorMethod<[], Array<[Principal,
|
|
102
|
+
list_satellite_configs: ActorMethod<[], Array<[Principal, OrbiterSatelliteConfig]>>;
|
|
98
103
|
set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
|
|
99
104
|
set_page_view: ActorMethod<[AnalyticKey, SetPageView], Result>;
|
|
100
105
|
set_page_views: ActorMethod<[Array<[AnalyticKey, SetPageView]>], Result_1>;
|
|
101
106
|
set_satellite_configs: ActorMethod<
|
|
102
107
|
[Array<[Principal, SetSatelliteConfig]>],
|
|
103
|
-
Array<[Principal,
|
|
108
|
+
Array<[Principal, OrbiterSatelliteConfig]>
|
|
104
109
|
>;
|
|
105
110
|
set_track_event: ActorMethod<[AnalyticKey, SetTrackEvent], Result_2>;
|
|
106
111
|
set_track_events: ActorMethod<[Array<[AnalyticKey, SetTrackEvent]>], Result_1>;
|
|
@@ -15,6 +15,10 @@ export const idlFactory = ({IDL}) => {
|
|
|
15
15
|
expires_at: IDL.Opt(IDL.Nat64)
|
|
16
16
|
});
|
|
17
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
|
+
});
|
|
18
22
|
const GetAnalytics = IDL.Record({
|
|
19
23
|
to: IDL.Opt(IDL.Nat64),
|
|
20
24
|
from: IDL.Opt(IDL.Nat64),
|
|
@@ -48,7 +52,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
48
52
|
created_at: IDL.Nat64,
|
|
49
53
|
satellite_id: IDL.Principal
|
|
50
54
|
});
|
|
51
|
-
const
|
|
55
|
+
const OrbiterSatelliteConfig = IDL.Record({
|
|
52
56
|
updated_at: IDL.Nat64,
|
|
53
57
|
created_at: IDL.Nat64,
|
|
54
58
|
enabled: IDL.Bool
|
|
@@ -98,6 +102,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
98
102
|
[]
|
|
99
103
|
),
|
|
100
104
|
del_satellite_config: IDL.Func([IDL.Principal, DelSatelliteConfig], [], []),
|
|
105
|
+
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
101
106
|
get_page_views: IDL.Func(
|
|
102
107
|
[GetAnalytics],
|
|
103
108
|
[IDL.Vec(IDL.Tuple(AnalyticKey, PageView))],
|
|
@@ -111,7 +116,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
111
116
|
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
112
117
|
list_satellite_configs: IDL.Func(
|
|
113
118
|
[],
|
|
114
|
-
[IDL.Vec(IDL.Tuple(IDL.Principal,
|
|
119
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, OrbiterSatelliteConfig))],
|
|
115
120
|
['query']
|
|
116
121
|
),
|
|
117
122
|
set_controllers: IDL.Func(
|
|
@@ -123,7 +128,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
123
128
|
set_page_views: IDL.Func([IDL.Vec(IDL.Tuple(AnalyticKey, SetPageView))], [Result_1], []),
|
|
124
129
|
set_satellite_configs: IDL.Func(
|
|
125
130
|
[IDL.Vec(IDL.Tuple(IDL.Principal, SetSatelliteConfig))],
|
|
126
|
-
[IDL.Vec(IDL.Tuple(IDL.Principal,
|
|
131
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, OrbiterSatelliteConfig))],
|
|
127
132
|
[]
|
|
128
133
|
),
|
|
129
134
|
set_track_event: IDL.Func([AnalyticKey, SetTrackEvent], [Result_2], []),
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var y=e=>e==null,
|
|
1
|
+
var g="abcdefghijklmnopqrstuvwxyz234567",i=Object.create(null);for(let e=0;e<g.length;e++)i[g[e]]=e;i[0]=i.o;i[1]=i.i;var M=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);var y=e=>e==null,b=e=>!y(e),I=class extends Error{},n=(e,t)=>{if(y(e))throw new I(t)};var c=e=>b(e)?[e]:[];var l=()=>typeof window<"u";var x=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,r)=>(r&=63,r<36?t+=r.toString(36):r<62?t+=(r-26).toString(36).toUpperCase():r>62?t+="-":t+="_",t),"");var w=()=>BigInt(Date.now())*BigInt(1e6);var p=()=>({collected_at:w(),updated_at:[]}),u=()=>{let{userAgent:e}=navigator;return{user_agent:c(e)}};var S=()=>{if(!(typeof crypto>"u"))return x()},d=S(),a,h=e=>{let{path:t}=e.worker??{},r=t===void 0?"./workers/analytics.worker.js":t;a=new Worker(r);let o=()=>console.warn("Unable to connect to the analytics web worker. Have you deployed it?");return a?.addEventListener("error",o,!1),P(e),{cleanup(){a?.removeEventListener("error",o,!1)}}},_=()=>{let e=async()=>await k(),t=new Proxy(history.pushState,{apply:async(r,o,f)=>{r.apply(o,f),await e()}});return history.pushState=t,addEventListener("popstate",e,{passive:!0}),{cleanup(){t=null,removeEventListener("popstate",e,!1)}}},s="Analytics worker not initialized. Did you call `initOrbiter`?",v="No session ID initialized.",m=async()=>{if(!l())return;n(d,v);let{title:e,location:{href:t},referrer:r}=document,{innerWidth:o,innerHeight:f}=window,{timeZone:N}=Intl.DateTimeFormat().resolvedOptions(),T={title:e,href:t,referrer:c(b(r)&&r!==""?r:void 0),device:{inner_width:o,inner_height:f},time_zone:N,session_id:d,...u(),...p()};await(await import("./idb.services-V6IDWAXJ.js")).setPageView({key:x(),view:T})},k=async()=>{n(a,s),await m(),a?.postMessage({msg:"junoTrackPageView"})},U=async e=>{if(!l())return;n(d,v),n(a,s),await(await import("./idb.services-V6IDWAXJ.js")).setTrackEvent({key:x(),track:{...e,session_id:d,...u(),...p()}}),a?.postMessage({msg:"junoTrackEvent"})},P=e=>{n(a,s),a?.postMessage({msg:"junoInitEnvironment",data:e})},A=()=>{n(a,s),a?.postMessage({msg:"junoStartTrackTimer"})},E=()=>{n(a,s),a?.postMessage({msg:"junoStopTracker"})};var oe=async e=>{await m();let{cleanup:t}=h(e),{cleanup:r}=_();return A(),()=>{E(),t(),r()}};export{oe as initOrbiter,U as trackEvent,k as trackPageView};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../utils/src/utils/debounce.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": ["/* 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", "/** 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 {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)], {\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());\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
|
-
"mappings": "
|
|
6
|
-
"names": ["isNullish", "argument", "nonNullish", "NullishError", "assertNonNullish", "value", "message", "toNullable", "isBrowser", "nanoid", "size", "id", "byte", "nowInBigIntNanoSeconds", "timestamp", "nowInBigIntNanoSeconds", "userAgent", "
|
|
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 workerC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iC,GAAc,MAAOC,GAA0C,CAE1E,MAAMC,EAAY,EAElB,GAAM,CAAC,QAASC,CAAa,EAAIC,EAAWH,CAAG,EAEzC,CAAC,QAASI,CAAkB,EAAIC,EAAmB,EAGzD,OAAAC,EAAc,EAEP,IAAM,CACXC,EAAa,EACbL,EAAc,EACdE,EAAmB,CACrB,CACF",
|
|
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
|
}
|
|
@@ -19,11 +19,20 @@ export interface DelSatelliteConfig {
|
|
|
19
19
|
export interface DeleteControllersArgs {
|
|
20
20
|
controllers: Array<Principal>;
|
|
21
21
|
}
|
|
22
|
+
export interface DepositCyclesArgs {
|
|
23
|
+
cycles: bigint;
|
|
24
|
+
destination_id: Principal;
|
|
25
|
+
}
|
|
22
26
|
export interface GetAnalytics {
|
|
23
27
|
to: [] | [bigint];
|
|
24
28
|
from: [] | [bigint];
|
|
25
29
|
satellite_id: [] | [Principal];
|
|
26
30
|
}
|
|
31
|
+
export interface OrbiterSatelliteConfig {
|
|
32
|
+
updated_at: bigint;
|
|
33
|
+
created_at: bigint;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
}
|
|
27
36
|
export interface PageView {
|
|
28
37
|
title: string;
|
|
29
38
|
updated_at: bigint;
|
|
@@ -43,11 +52,6 @@ export interface PageViewDevice {
|
|
|
43
52
|
export type Result = {Ok: PageView} | {Err: string};
|
|
44
53
|
export type Result_1 = {Ok: null} | {Err: Array<[AnalyticKey, string]>};
|
|
45
54
|
export type Result_2 = {Ok: TrackEvent} | {Err: string};
|
|
46
|
-
export interface SatelliteConfig {
|
|
47
|
-
updated_at: bigint;
|
|
48
|
-
created_at: bigint;
|
|
49
|
-
enabled: boolean;
|
|
50
|
-
}
|
|
51
55
|
export interface SetController {
|
|
52
56
|
metadata: Array<[string, string]>;
|
|
53
57
|
scope: ControllerScope;
|
|
@@ -91,16 +95,17 @@ export interface TrackEvent {
|
|
|
91
95
|
export interface _SERVICE {
|
|
92
96
|
del_controllers: ActorMethod<[DeleteControllersArgs], Array<[Principal, Controller]>>;
|
|
93
97
|
del_satellite_config: ActorMethod<[Principal, DelSatelliteConfig], undefined>;
|
|
98
|
+
deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
|
|
94
99
|
get_page_views: ActorMethod<[GetAnalytics], Array<[AnalyticKey, PageView]>>;
|
|
95
100
|
get_track_events: ActorMethod<[GetAnalytics], Array<[AnalyticKey, TrackEvent]>>;
|
|
96
101
|
list_controllers: ActorMethod<[], Array<[Principal, Controller]>>;
|
|
97
|
-
list_satellite_configs: ActorMethod<[], Array<[Principal,
|
|
102
|
+
list_satellite_configs: ActorMethod<[], Array<[Principal, OrbiterSatelliteConfig]>>;
|
|
98
103
|
set_controllers: ActorMethod<[SetControllersArgs], Array<[Principal, Controller]>>;
|
|
99
104
|
set_page_view: ActorMethod<[AnalyticKey, SetPageView], Result>;
|
|
100
105
|
set_page_views: ActorMethod<[Array<[AnalyticKey, SetPageView]>], Result_1>;
|
|
101
106
|
set_satellite_configs: ActorMethod<
|
|
102
107
|
[Array<[Principal, SetSatelliteConfig]>],
|
|
103
|
-
Array<[Principal,
|
|
108
|
+
Array<[Principal, OrbiterSatelliteConfig]>
|
|
104
109
|
>;
|
|
105
110
|
set_track_event: ActorMethod<[AnalyticKey, SetTrackEvent], Result_2>;
|
|
106
111
|
set_track_events: ActorMethod<[Array<[AnalyticKey, SetTrackEvent]>], Result_1>;
|
|
@@ -15,6 +15,10 @@ export const idlFactory = ({IDL}) => {
|
|
|
15
15
|
expires_at: IDL.Opt(IDL.Nat64)
|
|
16
16
|
});
|
|
17
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
|
+
});
|
|
18
22
|
const GetAnalytics = IDL.Record({
|
|
19
23
|
to: IDL.Opt(IDL.Nat64),
|
|
20
24
|
from: IDL.Opt(IDL.Nat64),
|
|
@@ -48,7 +52,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
48
52
|
created_at: IDL.Nat64,
|
|
49
53
|
satellite_id: IDL.Principal
|
|
50
54
|
});
|
|
51
|
-
const
|
|
55
|
+
const OrbiterSatelliteConfig = IDL.Record({
|
|
52
56
|
updated_at: IDL.Nat64,
|
|
53
57
|
created_at: IDL.Nat64,
|
|
54
58
|
enabled: IDL.Bool
|
|
@@ -98,6 +102,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
98
102
|
[]
|
|
99
103
|
),
|
|
100
104
|
del_satellite_config: IDL.Func([IDL.Principal, DelSatelliteConfig], [], []),
|
|
105
|
+
deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
|
|
101
106
|
get_page_views: IDL.Func(
|
|
102
107
|
[GetAnalytics],
|
|
103
108
|
[IDL.Vec(IDL.Tuple(AnalyticKey, PageView))],
|
|
@@ -111,7 +116,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
111
116
|
list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']),
|
|
112
117
|
list_satellite_configs: IDL.Func(
|
|
113
118
|
[],
|
|
114
|
-
[IDL.Vec(IDL.Tuple(IDL.Principal,
|
|
119
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, OrbiterSatelliteConfig))],
|
|
115
120
|
['query']
|
|
116
121
|
),
|
|
117
122
|
set_controllers: IDL.Func(
|
|
@@ -123,7 +128,7 @@ export const idlFactory = ({IDL}) => {
|
|
|
123
128
|
set_page_views: IDL.Func([IDL.Vec(IDL.Tuple(AnalyticKey, SetPageView))], [Result_1], []),
|
|
124
129
|
set_satellite_configs: IDL.Func(
|
|
125
130
|
[IDL.Vec(IDL.Tuple(IDL.Principal, SetSatelliteConfig))],
|
|
126
|
-
[IDL.Vec(IDL.Tuple(IDL.Principal,
|
|
131
|
+
[IDL.Vec(IDL.Tuple(IDL.Principal, OrbiterSatelliteConfig))],
|
|
127
132
|
[]
|
|
128
133
|
),
|
|
129
134
|
set_track_event: IDL.Func([AnalyticKey, SetTrackEvent], [Result_2], []),
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
var C=Object.defineProperty;var _=(e,t)=>()=>(e&&(t=e(e=0)),t);var G=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0})};function c(e){return new Promise((t,n)=>{e.oncomplete=e.onsuccess=()=>t(e.result),e.onabort=e.onerror=()=>n(e.error)})}function g(e,t){let n=indexedDB.open(e);n.onupgradeneeded=()=>n.result.createObjectStore(t);let r=c(n);return(i,u)=>r.then(p=>u(p.transaction(t,i).objectStore(t)))}function I(){return E||(E=g("keyval-store","keyval")),E}function P(e,t,n=I()){return n("readwrite",r=>(r.put(t,e),c(r.transaction)))}function b(e,t=I()){return t("readwrite",n=>(e.forEach(r=>n.delete(r)),c(n.transaction)))}function Z(e,t){return e.openCursor().onsuccess=function(){this.result&&(t(this.result),this.result.continue())},c(e.transaction)}function x(e=I()){return e("readonly",t=>{if(t.getAll&&t.getAllKeys)return Promise.all([c(t.getAllKeys()),c(t.getAll())]).then(([r,i])=>r.map((u,p)=>[u,i[p]]));let n=[];return e("readonly",r=>Z(r,i=>n.push([i.key,i.value])).then(()=>n))})}var E,K=_(()=>{});var A={};G(A,{delPageViews:()=>Y,delTrackEvents:()=>ee,getPageViews:()=>X,getTrackEvents:()=>q,setPageView:()=>Q,setTrackEvent:()=>$});var T,S,Q,X,Y,$,q,ee,N=_(()=>{"use strict";K();T=g("juno-views","views"),S=g("juno-events","events"),Q=({key:e,view:t})=>P(e,t,T),X=()=>x(T),Y=e=>b(e,T),$=({key:e,track:t})=>P(e,t,S),q=()=>x(S),ee=e=>b(e,S)});var D=e=>e==null,w=e=>!D(e),H=class extends Error{},a=(e,t)=>{if(D(e))throw new H(t)},m=e=>w(e)?[e]:[];var v=()=>typeof window<"u";import{randomFillSync as B}from"crypto";var M="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var z=128,s,l,J=e=>{!s||s.length<e?(s=Buffer.allocUnsafe(e*z),B(s),l=0):l+e>s.length&&(B(s),l=0),l+=e};var f=(e=21)=>{J(e-=0);let t="";for(let n=l-e;n<l;n++)t+=M[s[n]&63];return t};var j=()=>BigInt(Date.now())*BigInt(1e6);var k=()=>({collected_at:j(),updated_at:[]}),h=()=>{let{userAgent:e}=navigator;return{user_agent:m(e)}};var te=()=>{if(!(typeof crypto>"u"))return f()},y=te(),o,O=e=>{let{path:t}=e.worker??{},n=t===void 0?"./workers/analytics.worker.js":t;o=new Worker(n);let r=()=>console.warn("Unable to connect to the analytics web worker. Have you deployed it?");return o?.addEventListener("error",r,!1),re(e),{cleanup(){o?.removeEventListener("error",r,!1)}}},U=()=>{let e=async()=>await L(),t=new Proxy(history.pushState,{apply:async(n,r,i)=>{n.apply(r,i),await e()}});return history.pushState=t,addEventListener("popstate",e,{passive:!0}),{cleanup(){t=null,removeEventListener("popstate",e,!1)}}},d="Analytics worker not initialized. Did you call `initOrbiter`?",W="No session ID initialized.",V=async()=>{if(!v())return;a(y,W);let{title:e,location:{href:t},referrer:n}=document,{innerWidth:r,innerHeight:i}=window,{timeZone:u}=Intl.DateTimeFormat().resolvedOptions(),p={title:e,href:t,referrer:m(w(n)&&n!==""?n:void 0),device:{inner_width:r,inner_height:i},time_zone:u,session_id:y,...h(),...k()};await(await Promise.resolve().then(()=>(N(),A))).setPageView({key:f(),view:p})},L=async()=>{a(o,d),await V(),o?.postMessage({msg:"junoTrackPageView"})},ne=async e=>{if(!v())return;a(y,W),a(o,d),await(await Promise.resolve().then(()=>(N(),A))).setTrackEvent({key:f(),track:{...e,session_id:y,...h(),...k()}}),o?.postMessage({msg:"junoTrackEvent"})},re=e=>{a(o,d),o?.postMessage({msg:"junoInitEnvironment",data:e})},R=()=>{a(o,d),o?.postMessage({msg:"junoStartTrackTimer"})},F=()=>{a(o,d),o?.postMessage({msg:"junoStopTracker"})};var Pe=async e=>{await V();let{cleanup:t}=O(e),{cleanup:n}=U();return R(),()=>{F(),t(),n()}};export{Pe as initOrbiter,ne as trackEvent,L as trackPageView};
|
|
3
|
+
var qe=Object.create;var G=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty;var Xe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ye=(e,t)=>()=>(e&&(t=e(e=0)),t);var h=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ze=(e,t)=>{for(var r in t)G(e,r,{get:t[r],enumerable:!0})},Ze=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Je(t))!Ye.call(e,o)&&o!==r&&G(e,o,{get:()=>t[o],enumerable:!(n=Ge(t,o))||n.enumerable});return e};var Qe=(e,t,r)=>(r=e!=null?qe($e(e)):{},Ze(t||!e||!e.__esModule?G(r,"default",{value:e,enumerable:!0}):r,e));var ge=h(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.decode=k.encode=void 0;var S="abcdefghijklmnopqrstuvwxyz234567",E=Object.create(null);for(let e=0;e<S.length;e++)E[S[e]]=e;E[0]=E.o;E[1]=E.i;function et(e){let t=0,r=0,n="";function o(s){return t<0?r|=s>>-t:r=s<<t&248,t>3?(t-=8,1):(t<4&&(n+=S[r>>3],t+=5),0)}for(let s=0;s<e.length;)s+=o(e[s]);return n+(t<0?S[r>>3]:"")}k.encode=et;function tt(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function s(i){let c=E[i.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);c<<=3,r|=c>>>t,t+=5,t>=8&&(n[o++]=r,t-=8,t>0?r=c<<5-t&255:r=0)}for(let i of e)s(i);return n.slice(0,o)}k.decode=tt});var we=h(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.getCrc32=void 0;var rt=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function nt(e){let t=new Uint8Array(e),r=-1;for(let n=0;n<t.length;n++){let s=(t[n]^r)&255;r=rt[s]^r>>>8}return(r^-1)>>>0}L.getCrc32=nt});var Ee=h(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u.output=u.exists=u.hash=u.bytes=u.bool=u.number=void 0;function N(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}u.number=N;function me(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}u.bool=me;function ot(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function J(e,...t){if(!ot(e))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}u.bytes=J;function _e(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");N(e.outputLen),N(e.blockLen)}u.hash=_e;function ve(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}u.exists=ve;function Ae(e,t){J(e);let r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}u.output=Ae;var st={number:N,bool:me,bytes:J,hash:_e,exists:ve,output:Ae};u.default=st});var ke=h(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.crypto=void 0;var j=Xe("node:crypto");C.crypto=j&&typeof j=="object"&&"webcrypto"in j?j.webcrypto:void 0});var z=h(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.randomBytes=a.wrapXOFConstructorWithOpts=a.wrapConstructorWithOpts=a.wrapConstructor=a.checkOpts=a.Hash=a.concatBytes=a.toBytes=a.utf8ToBytes=a.asyncLoop=a.nextTick=a.hexToBytes=a.bytesToHex=a.isLE=a.rotr=a.createView=a.u32=a.u8=void 0;var $=ke(),it=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength);a.u8=it;var at=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));a.u32=at;function X(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}var ct=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);a.createView=ct;var ft=(e,t)=>e<<32-t|e>>>t;a.rotr=ft;a.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!a.isLE)throw new Error("Non little-endian hardware is not supported");var dt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ut(e){if(!X(e))throw new Error("Uint8Array expected");let t="";for(let r=0;r<e.length;r++)t+=dt[e[r]];return t}a.bytesToHex=ut;var y={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Ie(e){if(e>=y._0&&e<=y._9)return e-y._0;if(e>=y._A&&e<=y._F)return e-(y._A-10);if(e>=y._a&&e<=y._f)return e-(y._a-10)}function xt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length,r=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ie(e.charCodeAt(s)),c=Ie(e.charCodeAt(s+1));if(i===void 0||c===void 0){let d=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+d+'" at index '+s)}n[o]=i*16+c}return n}a.hexToBytes=xt;var lt=async()=>{};a.nextTick=lt;async function bt(e,t,r){let n=Date.now();for(let o=0;o<e;o++){r(o);let s=Date.now()-n;s>=0&&s<t||(await(0,a.nextTick)(),n+=s)}}a.asyncLoop=bt;function Pe(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}a.utf8ToBytes=Pe;function V(e){if(typeof e=="string"&&(e=Pe(e)),!X(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}a.toBytes=V;function pt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];if(!X(o))throw new Error("Uint8Array expected");t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}a.concatBytes=pt;var Y=class{clone(){return this._cloneInto()}};a.Hash=Y;var ht={}.toString;function yt(e,t){if(t!==void 0&&ht.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}a.checkOpts=yt;function gt(e){let t=n=>e().update(V(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}a.wrapConstructor=gt;function wt(e){let t=(n,o)=>e(o).update(V(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}a.wrapConstructorWithOpts=wt;function mt(e){let t=(n,o)=>e(o).update(V(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}a.wrapXOFConstructorWithOpts=mt;function _t(e=32){if($.crypto&&typeof $.crypto.getRandomValues=="function")return $.crypto.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}a.randomBytes=_t});var Te=h(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.SHA2=void 0;var Z=Ee(),O=z();function vt(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),d=n?4:0,b=n?0:4;e.setUint32(t+d,i,n),e.setUint32(t+b,c,n)}var Q=class extends O.Hash{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,O.createView)(this.buffer)}update(t){(0,Z.exists)(this);let{view:r,buffer:n,blockLen:o}=this;t=(0,O.toBytes)(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let d=(0,O.createView)(t);for(;o<=s-i;i+=o)this.process(d,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Z.exists)(this),(0,Z.output)(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;vt(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=(0,O.createView)(t),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let b=d/4,g=this.get();if(b>g.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<b;f++)c.setUint32(4*f,g[f],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%r&&t.buffer.set(n),t}};M.SHA2=Q});var Ue=h(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.sha224=I.sha256=void 0;var At=Te(),l=z(),Et=(e,t,r)=>e&t^~e&r,kt=(e,t,r)=>e&t^e&r^t&r,It=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),w=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),m=new Uint32Array(64),D=class extends At.SHA2{constructor(){super(64,32,8,!1),this.A=w[0]|0,this.B=w[1]|0,this.C=w[2]|0,this.D=w[3]|0,this.E=w[4]|0,this.F=w[5]|0,this.G=w[6]|0,this.H=w[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:d}=this;return[t,r,n,o,s,i,c,d]}set(t,r,n,o,s,i,c,d){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=d|0}process(t,r){for(let f=0;f<16;f++,r+=4)m[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let U=m[f-15],A=m[f-2],he=(0,l.rotr)(U,7)^(0,l.rotr)(U,18)^U>>>3,q=(0,l.rotr)(A,17)^(0,l.rotr)(A,19)^A>>>10;m[f]=q+m[f-7]+he+m[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:d,G:b,H:g}=this;for(let f=0;f<64;f++){let U=(0,l.rotr)(c,6)^(0,l.rotr)(c,11)^(0,l.rotr)(c,25),A=g+U+Et(c,d,b)+It[f]+m[f]|0,q=((0,l.rotr)(n,2)^(0,l.rotr)(n,13)^(0,l.rotr)(n,22))+kt(n,o,s)|0;g=b,b=d,d=c,c=i+A|0,i=s,s=o,o=n,n=A+q|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,d=d+this.F|0,b=b+this.G|0,g=g+this.H|0,this.set(n,o,s,i,c,d,b,g)}roundClean(){m.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},ee=class extends D{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};I.sha256=(0,l.wrapConstructor)(()=>new D);I.sha224=(0,l.wrapConstructor)(()=>new ee)});var Oe=h(H=>{"use strict";Object.defineProperty(H,"__esModule",{value:!0});H.sha224=void 0;var Pt=Ue();function Tt(e){return Pt.sha224.create().update(new Uint8Array(e)).digest()}H.sha224=Tt});var Le=h(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.Principal=p.JSON_KEY_PRINCIPAL=void 0;var Be=ge(),Ut=we(),Ot=Oe();p.JSON_KEY_PRINCIPAL="__principal__";var Bt=2,Se=4,St="aaaaa-aa",Lt=e=>{var t;return new Uint8Array(((t=e.match(/.{1,2}/g))!==null&&t!==void 0?t:[]).map(r=>parseInt(r,16)))},Nt=e=>e.reduce((t,r)=>t+r.toString(16).padStart(2,"0"),""),te=class e{constructor(t){this._arr=t,this._isPrincipal=!0}static anonymous(){return new this(new Uint8Array([Se]))}static managementCanister(){return this.fromHex(St)}static selfAuthenticating(t){let r=(0,Ot.sha224)(t);return new this(new Uint8Array([...r,Bt]))}static from(t){if(typeof t=="string")return e.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new e(t);if(typeof t=="object"&&t!==null&&t._isPrincipal===!0)return new e(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(Lt(t))}static fromText(t){let r=t;if(t.includes(p.JSON_KEY_PRINCIPAL)){let i=JSON.parse(t);p.JSON_KEY_PRINCIPAL in i&&(r=i[p.JSON_KEY_PRINCIPAL])}let n=r.toLowerCase().replace(/-/g,""),o=(0,Be.decode)(n);o=o.slice(4,o.length);let s=new this(o);if(s.toText()!==r)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return s}static fromUint8Array(t){return new this(t)}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===Se}toUint8Array(){return this._arr}toHex(){return Nt(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,(0,Ut.getCrc32)(this._arr));let n=new Uint8Array(t),o=Uint8Array.from(this._arr),s=new Uint8Array([...n,...o]),c=(0,Be.encode)(s).match(/.{1,5}/g);if(!c)throw new Error;return c.join("-")}toString(){return this.toText()}toJSON(){return{[p.JSON_KEY_PRINCIPAL]:this.toText()}}compareTo(t){for(let r=0;r<Math.min(this._arr.length,t._arr.length);r++){if(this._arr[r]<t._arr[r])return"lt";if(this._arr[r]>t._arr[r])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){let r=this.compareTo(t);return r=="lt"||r=="eq"}gtEq(t){let r=this.compareTo(t);return r=="gt"||r=="eq"}};p.Principal=te});function T(e){return new Promise((t,r)=>{e.oncomplete=e.onsuccess=()=>t(e.result),e.onabort=e.onerror=()=>r(e.error)})}function W(e,t){let r=indexedDB.open(e);r.onupgradeneeded=()=>r.result.createObjectStore(t);let n=T(r);return(o,s)=>n.then(i=>s(i.transaction(t,o).objectStore(t)))}function ae(){return ie||(ie=W("keyval-store","keyval")),ie}function ce(e,t,r=ae()){return r("readwrite",n=>(n.put(t,e),T(n.transaction)))}function fe(e,t=ae()){return t("readwrite",r=>(e.forEach(n=>r.delete(n)),T(r.transaction)))}function Dt(e,t){return e.openCursor().onsuccess=function(){this.result&&(t(this.result),this.result.continue())},T(e.transaction)}function de(e=ae()){return e("readonly",t=>{if(t.getAll&&t.getAllKeys)return Promise.all([T(t.getAllKeys()),T(t.getAll())]).then(([n,o])=>n.map((s,i)=>[s,o[i]]));let r=[];return e("readonly",n=>Dt(n,o=>r.push([o.key,o.value])).then(()=>r))})}var ie,Me=ye(()=>{});var le={};ze(le,{delPageViews:()=>Rt,delTrackEvents:()=>qt,getPageViews:()=>Ft,getTrackEvents:()=>Kt,setPageView:()=>Ht,setTrackEvent:()=>Wt});var ue,xe,Ht,Ft,Rt,Wt,Kt,qt,be=ye(()=>{"use strict";Me();ue=W("juno-views","views"),xe=W("juno-events","events"),Ht=({key:e,view:t})=>ce(e,t,ue),Ft=()=>de(ue),Rt=e=>fe(e,ue),Wt=({key:e,track:t})=>ce(e,t,xe),Kt=()=>de(xe),qt=e=>fe(e,xe)});var jt=Qe(Le(),1);var Ne=e=>e==null,re=e=>!Ne(e),Ct=class extends Error{},_=(e,t)=>{if(Ne(e))throw new Ct(t)};var F=e=>re(e)?[e]:[];var ne=()=>typeof window<"u";import{randomFillSync as Ce}from"crypto";var je="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var Vt=128,v,P,Mt=e=>{!v||v.length<e?(v=Buffer.allocUnsafe(e*Vt),Ce(v),P=0):P+e>v.length&&(Ce(v),P=0),P+=e};var R=(e=21)=>{Mt(e-=0);let t="";for(let r=P-e;r<P;r++)t+=je[v[r]&63];return t};var Ve=()=>BigInt(Date.now())*BigInt(1e6);var oe=()=>({collected_at:Ve(),updated_at:[]}),se=()=>{let{userAgent:e}=navigator;return{user_agent:F(e)}};var Gt=()=>{if(!(typeof crypto>"u"))return R()},K=Gt(),x,De=e=>{let{path:t}=e.worker??{},r=t===void 0?"./workers/analytics.worker.js":t;x=new Worker(r);let n=()=>console.warn("Unable to connect to the analytics web worker. Have you deployed it?");return x?.addEventListener("error",n,!1),$t(e),{cleanup(){x?.removeEventListener("error",n,!1)}}},He=()=>{let e=async()=>await Re(),t=new Proxy(history.pushState,{apply:async(r,n,o)=>{r.apply(n,o),await e()}});return history.pushState=t,addEventListener("popstate",e,{passive:!0}),{cleanup(){t=null,removeEventListener("popstate",e,!1)}}},B="Analytics worker not initialized. Did you call `initOrbiter`?",Fe="No session ID initialized.",pe=async()=>{if(!ne())return;_(K,Fe);let{title:e,location:{href:t},referrer:r}=document,{innerWidth:n,innerHeight:o}=window,{timeZone:s}=Intl.DateTimeFormat().resolvedOptions(),i={title:e,href:t,referrer:F(re(r)&&r!==""?r:void 0),device:{inner_width:n,inner_height:o},time_zone:s,session_id:K,...se(),...oe()};await(await Promise.resolve().then(()=>(be(),le))).setPageView({key:R(),view:i})},Re=async()=>{_(x,B),await pe(),x?.postMessage({msg:"junoTrackPageView"})},Jt=async e=>{if(!ne())return;_(K,Fe),_(x,B),await(await Promise.resolve().then(()=>(be(),le))).setTrackEvent({key:R(),track:{...e,session_id:K,...se(),...oe()}}),x?.postMessage({msg:"junoTrackEvent"})},$t=e=>{_(x,B),x?.postMessage({msg:"junoInitEnvironment",data:e})},We=()=>{_(x,B),x?.postMessage({msg:"junoStartTrackTimer"})},Ke=()=>{_(x,B),x?.postMessage({msg:"junoStopTracker"})};var vr=async e=>{await pe();let{cleanup:t}=De(e),{cleanup:r}=He();return We(),()=>{Ke(),t(),r()}};export{vr as initOrbiter,Jt as trackEvent,Re as trackPageView};
|
|
4
|
+
/*! Bundled license information:
|
|
5
|
+
|
|
6
|
+
@noble/hashes/utils.js:
|
|
7
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8
|
+
*/
|
|
4
9
|
//# sourceMappingURL=index.mjs.map
|