@moser-inc/moser-labs-custom-elements 2.5.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/dist/external/index.d.ts +511 -0
- package/dist/external/index.js +408 -0
- package/dist/index.d.ts +511 -0
- package/dist/index.js +12604 -0
- package/package.json +50 -40
- package/dist/external/moser-labs-custom-elements.d.ts +0 -42
- package/dist/external/moser-labs-custom-elements.js +0 -320
- package/dist/moser-labs-custom-elements.d.ts +0 -42
- package/dist/moser-labs-custom-elements.js +0 -11045
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ This package contains a collection of custom elements that can be used in any we
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm i @moser-inc/moser-labs-custom-elements
|
|
8
|
+
npm i @moser-inc/moser-labs-custom-elements @moser-inc/moser-labs-themes
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -13,6 +13,7 @@ npm i @moser-inc/moser-labs-custom-elements
|
|
|
13
13
|
For these custom elements to function properly, you must first authenticate the user with Keycloak before calling the provided `registerCustomElements` function, passing the Keycloak instance to it.
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
+
import Labs from '@moser-inc/moser-labs-themes/labs';
|
|
16
17
|
import Keycloak from 'keycloak-js';
|
|
17
18
|
import { registerCustomElements } from '@moser-inc/moser-labs-custom-elements';
|
|
18
19
|
|
|
@@ -21,7 +22,10 @@ const keycloak = new Keycloak('/keycloak.json');
|
|
|
21
22
|
keycloak.init({ onLoad: 'login-required' }).then((isAuthenticated) => {
|
|
22
23
|
if (!isAuthenticated) return;
|
|
23
24
|
|
|
24
|
-
registerCustomElements({
|
|
25
|
+
registerCustomElements({
|
|
26
|
+
preset: Labs,
|
|
27
|
+
keycloak,
|
|
28
|
+
});
|
|
25
29
|
});
|
|
26
30
|
```
|
|
27
31
|
|
|
@@ -30,7 +34,11 @@ keycloak.init({ onLoad: 'login-required' }).then((isAuthenticated) => {
|
|
|
30
34
|
In order for the custom elements to use the correct instance for calling API endpoints and getting profile pictures, pass the `apiUri` option to `registerCustomElements`, using an environment variable for it to be dynamic between staging and production. It defaults to using `window.location.origin`.
|
|
31
35
|
|
|
32
36
|
```ts
|
|
33
|
-
registerCustomElements({
|
|
37
|
+
registerCustomElements({
|
|
38
|
+
preset: Labs,
|
|
39
|
+
keycloak,
|
|
40
|
+
apiUri: import.meta.env.VITE_API_URI,
|
|
41
|
+
});
|
|
34
42
|
```
|
|
35
43
|
|
|
36
44
|
## External
|
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import { Preset } from "@moser-inc/moser-labs-themes";
|
|
2
|
+
import Keycloak from "keycloak-js";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/analytics/lib/types.d.ts
|
|
5
|
+
declare module "analytics" {
|
|
6
|
+
/**
|
|
7
|
+
* Core Analytic constants. These are exposed for third party plugins & listeners
|
|
8
|
+
* @property ANON_ID - Anonymous visitor Id localstorage key
|
|
9
|
+
* @property USER_ID - Visitor Id localstorage key
|
|
10
|
+
* @property USER_TRAITS - Visitor traits localstorage key
|
|
11
|
+
*/
|
|
12
|
+
type constants = {
|
|
13
|
+
ANON_ID: ANON_ID;
|
|
14
|
+
USER_ID: USER_ID;
|
|
15
|
+
USER_TRAITS: USER_TRAITS;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Anonymous visitor Id localstorage key
|
|
19
|
+
*/
|
|
20
|
+
type ANON_ID = string;
|
|
21
|
+
/**
|
|
22
|
+
* Visitor Id localstorage key
|
|
23
|
+
*/
|
|
24
|
+
type USER_ID = string;
|
|
25
|
+
/**
|
|
26
|
+
* Visitor traits localstorage key
|
|
27
|
+
*/
|
|
28
|
+
type USER_TRAITS = string;
|
|
29
|
+
/**
|
|
30
|
+
* Analytics library configuration
|
|
31
|
+
*
|
|
32
|
+
* After the library is initialized with config, the core API is exposed & ready for use in the application.
|
|
33
|
+
* @example
|
|
34
|
+
* import Analytics from 'analytics'
|
|
35
|
+
* import pluginABC from 'analytics-plugin-abc'
|
|
36
|
+
* import pluginXYZ from 'analytics-plugin-xyz'
|
|
37
|
+
*
|
|
38
|
+
* // initialize analytics
|
|
39
|
+
* const analytics = Analytics({
|
|
40
|
+
* app: 'my-awesome-app',
|
|
41
|
+
* plugins: [
|
|
42
|
+
* pluginABC,
|
|
43
|
+
* pluginXYZ
|
|
44
|
+
* ]
|
|
45
|
+
* })
|
|
46
|
+
* @param config - analytics core config
|
|
47
|
+
* @param [config.app] - Name of site / app
|
|
48
|
+
* @param [config.version] - Version of your app
|
|
49
|
+
* @param [config.debug] - Should analytics run in debug mode
|
|
50
|
+
* @param [config.plugins] - Array of analytics plugins
|
|
51
|
+
* @returns Analytics Instance
|
|
52
|
+
*/
|
|
53
|
+
function analytics(config: {
|
|
54
|
+
app?: string;
|
|
55
|
+
version?: string | number;
|
|
56
|
+
debug?: boolean;
|
|
57
|
+
plugins?: AnalyticsPlugin[];
|
|
58
|
+
}): AnalyticsInstance;
|
|
59
|
+
/**
|
|
60
|
+
* Async Management methods for plugins.
|
|
61
|
+
*
|
|
62
|
+
* This is also where [custom methods](https://bit.ly/329vFXy) are loaded into the instance.
|
|
63
|
+
* @example
|
|
64
|
+
* // Enable a plugin by namespace
|
|
65
|
+
* analytics.plugins.enable('keenio')
|
|
66
|
+
*
|
|
67
|
+
* // Disable a plugin by namespace
|
|
68
|
+
* analytics.plugins.disable('google-analytics')
|
|
69
|
+
* @property enable - Set storage value
|
|
70
|
+
* @property disable - Remove storage value
|
|
71
|
+
*/
|
|
72
|
+
type Plugins = {
|
|
73
|
+
enable: EnablePlugin;
|
|
74
|
+
disable: DisablePlugin;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Enable analytics plugin
|
|
78
|
+
* @example
|
|
79
|
+
* analytics.plugins.enable('google-analytics').then(() => {
|
|
80
|
+
* console.log('do stuff')
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* // Enable multiple plugins at once
|
|
84
|
+
* analytics.plugins.enable(['google-analytics', 'segment']).then(() => {
|
|
85
|
+
* console.log('do stuff')
|
|
86
|
+
* })
|
|
87
|
+
* @param plugins - name of plugins(s) to disable
|
|
88
|
+
* @param [callback] - callback after enable runs
|
|
89
|
+
*/
|
|
90
|
+
type EnablePlugin = (plugins: string | string[], callback?: (...params: any[]) => any) => Promise<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Disable analytics plugin
|
|
93
|
+
* @example
|
|
94
|
+
* analytics.plugins.disable('google').then(() => {
|
|
95
|
+
* console.log('do stuff')
|
|
96
|
+
* })
|
|
97
|
+
*
|
|
98
|
+
* analytics.plugins.disable(['google', 'segment']).then(() => {
|
|
99
|
+
* console.log('do stuff')
|
|
100
|
+
* })
|
|
101
|
+
* @param plugins - name of integration(s) to disable
|
|
102
|
+
* @param [callback] - callback after disable runs
|
|
103
|
+
*/
|
|
104
|
+
type DisablePlugin = (plugins: string | string[], callback?: (...params: any[]) => any) => Promise<any>;
|
|
105
|
+
/**
|
|
106
|
+
* Analytic instance returned from initialization
|
|
107
|
+
* @property identify - Identify a user
|
|
108
|
+
* @property track - Track an analytics event
|
|
109
|
+
* @property page - Trigger page view
|
|
110
|
+
* @property user - Get user data
|
|
111
|
+
* @property reset - Clear information about user & reset analytics
|
|
112
|
+
* @property ready - Fire callback on analytics ready event
|
|
113
|
+
* @property on - Fire callback on analytics lifecycle events.
|
|
114
|
+
* @property once - Fire callback on analytics lifecycle events once.
|
|
115
|
+
* @property getState - Get data about user, activity, or context.
|
|
116
|
+
* @property storage - storage methods
|
|
117
|
+
* @property plugins - plugin methods
|
|
118
|
+
*/
|
|
119
|
+
export interface AnalyticsInstance {
|
|
120
|
+
identify: Identify;
|
|
121
|
+
track: Track;
|
|
122
|
+
page: Page;
|
|
123
|
+
user: User;
|
|
124
|
+
reset: Reset;
|
|
125
|
+
ready: Ready;
|
|
126
|
+
on: On;
|
|
127
|
+
once: Once;
|
|
128
|
+
getState: GetState;
|
|
129
|
+
storage: Storage;
|
|
130
|
+
plugins: Plugins;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Identify a user. This will trigger `identify` calls in any installed plugins and will set user data in localStorage
|
|
134
|
+
* @example
|
|
135
|
+
* // Basic user id identify
|
|
136
|
+
* analytics.identify('xyz-123')
|
|
137
|
+
*
|
|
138
|
+
* // Identify with additional traits
|
|
139
|
+
* analytics.identify('xyz-123', {
|
|
140
|
+
* name: 'steve',
|
|
141
|
+
* company: 'hello-clicky'
|
|
142
|
+
* })
|
|
143
|
+
*
|
|
144
|
+
* // Fire callback with 2nd or 3rd argument
|
|
145
|
+
* analytics.identify('xyz-123', () => {
|
|
146
|
+
* console.log('do this after identify')
|
|
147
|
+
* })
|
|
148
|
+
*
|
|
149
|
+
* // Disable sending user data to specific analytic tools
|
|
150
|
+
* analytics.identify('xyz-123', {}, {
|
|
151
|
+
* plugins: {
|
|
152
|
+
* // disable sending this identify call to segment
|
|
153
|
+
* segment: false
|
|
154
|
+
* }
|
|
155
|
+
* })
|
|
156
|
+
*
|
|
157
|
+
* // Send user data to only to specific analytic tools
|
|
158
|
+
* analytics.identify('xyz-123', {}, {
|
|
159
|
+
* plugins: {
|
|
160
|
+
* // disable this specific identify in all plugins except customerio
|
|
161
|
+
* all: false,
|
|
162
|
+
* customerio: true
|
|
163
|
+
* }
|
|
164
|
+
* })
|
|
165
|
+
* @param userId - Unique ID of user
|
|
166
|
+
* @param [traits] - Object of user traits
|
|
167
|
+
* @param [options] - Options to pass to identify call
|
|
168
|
+
* @param [callback] - Callback function after identify completes
|
|
169
|
+
*/
|
|
170
|
+
type Identify = (userId: string, traits?: any, options?: any, callback?: (...params: any[]) => any) => Promise<any>;
|
|
171
|
+
/**
|
|
172
|
+
* Track an analytics event. This will trigger `track` calls in any installed plugins
|
|
173
|
+
* @example
|
|
174
|
+
* // Basic event tracking
|
|
175
|
+
* analytics.track('buttonClicked')
|
|
176
|
+
*
|
|
177
|
+
* // Event tracking with payload
|
|
178
|
+
* analytics.track('itemPurchased', {
|
|
179
|
+
* price: 11,
|
|
180
|
+
* sku: '1234'
|
|
181
|
+
* })
|
|
182
|
+
*
|
|
183
|
+
* // Fire callback with 2nd or 3rd argument
|
|
184
|
+
* analytics.track('newsletterSubscribed', () => {
|
|
185
|
+
* console.log('do this after track')
|
|
186
|
+
* })
|
|
187
|
+
*
|
|
188
|
+
* // Disable sending this event to specific analytic tools
|
|
189
|
+
* analytics.track('cartAbandoned', {
|
|
190
|
+
* items: ['xyz', 'abc']
|
|
191
|
+
* }, {
|
|
192
|
+
* plugins: {
|
|
193
|
+
* // disable track event for segment
|
|
194
|
+
* segment: false
|
|
195
|
+
* }
|
|
196
|
+
* })
|
|
197
|
+
*
|
|
198
|
+
* // Send event to only to specific analytic tools
|
|
199
|
+
* analytics.track('customerIoOnlyEventExample', {
|
|
200
|
+
* price: 11,
|
|
201
|
+
* sku: '1234'
|
|
202
|
+
* }, {
|
|
203
|
+
* plugins: {
|
|
204
|
+
* // disable this specific track call all plugins except customerio
|
|
205
|
+
* all: false,
|
|
206
|
+
* customerio: true
|
|
207
|
+
* }
|
|
208
|
+
* })
|
|
209
|
+
* @param eventName - Event name
|
|
210
|
+
* @param [payload] - Event payload
|
|
211
|
+
* @param [options] - Event options
|
|
212
|
+
* @param [callback] - Callback to fire after tracking completes
|
|
213
|
+
*/
|
|
214
|
+
type Track = (eventName: string, payload?: any, options?: any, callback?: (...params: any[]) => any) => Promise<any>;
|
|
215
|
+
/**
|
|
216
|
+
* Trigger page view. This will trigger `page` calls in any installed plugins
|
|
217
|
+
* @example
|
|
218
|
+
* // Basic page tracking
|
|
219
|
+
* analytics.page()
|
|
220
|
+
*
|
|
221
|
+
* // Page tracking with page data overrides
|
|
222
|
+
* analytics.page({
|
|
223
|
+
* url: 'https://google.com'
|
|
224
|
+
* })
|
|
225
|
+
*
|
|
226
|
+
* // Fire callback with 1st, 2nd or 3rd argument
|
|
227
|
+
* analytics.page(() => {
|
|
228
|
+
* console.log('do this after page')
|
|
229
|
+
* })
|
|
230
|
+
*
|
|
231
|
+
* // Disable sending this pageview to specific analytic tools
|
|
232
|
+
* analytics.page({}, {
|
|
233
|
+
* plugins: {
|
|
234
|
+
* // disable page tracking event for segment
|
|
235
|
+
* segment: false
|
|
236
|
+
* }
|
|
237
|
+
* })
|
|
238
|
+
*
|
|
239
|
+
* // Send pageview to only to specific analytic tools
|
|
240
|
+
* analytics.page({}, {
|
|
241
|
+
* plugins: {
|
|
242
|
+
* // disable this specific page in all plugins except customerio
|
|
243
|
+
* all: false,
|
|
244
|
+
* customerio: true
|
|
245
|
+
* }
|
|
246
|
+
* })
|
|
247
|
+
* @param [data] - Page data overrides.
|
|
248
|
+
* @param [options] - Page tracking options
|
|
249
|
+
* @param [callback] - Callback to fire after page view call completes
|
|
250
|
+
*/
|
|
251
|
+
type Page = (data?: PageData, options?: any, callback?: (...params: any[]) => any) => Promise<any>;
|
|
252
|
+
/**
|
|
253
|
+
* Get user data
|
|
254
|
+
* @example
|
|
255
|
+
* // Get all user data
|
|
256
|
+
* const userData = analytics.user()
|
|
257
|
+
*
|
|
258
|
+
* // Get user id
|
|
259
|
+
* const userId = analytics.user('userId')
|
|
260
|
+
*
|
|
261
|
+
* // Get user company name
|
|
262
|
+
* const companyName = analytics.user('traits.company.name')
|
|
263
|
+
* @param [key] - dot.prop.path of user data. Example: 'traits.company.name'
|
|
264
|
+
*/
|
|
265
|
+
type User = (key?: string) => string & any;
|
|
266
|
+
/**
|
|
267
|
+
* Clear all information about the visitor & reset analytic state.
|
|
268
|
+
* @example
|
|
269
|
+
* // Reset current visitor
|
|
270
|
+
* analytics.reset()
|
|
271
|
+
* @param [callback] - Handler to run after reset
|
|
272
|
+
*/
|
|
273
|
+
type Reset = (callback?: (...params: any[]) => any) => Promise<any>;
|
|
274
|
+
/**
|
|
275
|
+
* Fire callback on analytics ready event
|
|
276
|
+
* @example
|
|
277
|
+
* analytics.ready((payload) => {
|
|
278
|
+
* console.log('all plugins have loaded or were skipped', payload);
|
|
279
|
+
* })
|
|
280
|
+
* @param callback - function to trigger when all providers have loaded
|
|
281
|
+
*/
|
|
282
|
+
type Ready = (callback: (...params: any[]) => any) => DetachListeners;
|
|
283
|
+
/**
|
|
284
|
+
* Attach an event handler function for analytics lifecycle events.
|
|
285
|
+
* @example
|
|
286
|
+
* // Fire function when 'track' calls happen
|
|
287
|
+
* analytics.on('track', ({ payload }) => {
|
|
288
|
+
* console.log('track call just happened. Do stuff')
|
|
289
|
+
* })
|
|
290
|
+
*
|
|
291
|
+
* // Remove listener before it is called
|
|
292
|
+
* const removeListener = analytics.on('track', ({ payload }) => {
|
|
293
|
+
* console.log('This will never get called')
|
|
294
|
+
* })
|
|
295
|
+
*
|
|
296
|
+
* // cleanup .on listener
|
|
297
|
+
* removeListener()
|
|
298
|
+
* @param name - Name of event to listen to
|
|
299
|
+
* @param callback - function to fire on event
|
|
300
|
+
*/
|
|
301
|
+
type On = (name: string, callback: (...params: any[]) => any) => DetachListeners;
|
|
302
|
+
/**
|
|
303
|
+
* Detach listeners
|
|
304
|
+
*/
|
|
305
|
+
export type DetachListeners = () => void;
|
|
306
|
+
/**
|
|
307
|
+
* Attach a handler function to an event and only trigger it once.
|
|
308
|
+
* @example
|
|
309
|
+
* // Fire function only once per 'track'
|
|
310
|
+
* analytics.once('track', ({ payload }) => {
|
|
311
|
+
* console.log('This is only triggered once when analytics.track() fires')
|
|
312
|
+
* })
|
|
313
|
+
*
|
|
314
|
+
* // Remove listener before it is called
|
|
315
|
+
* const listener = analytics.once('track', ({ payload }) => {
|
|
316
|
+
* console.log('This will never get called b/c listener() is called')
|
|
317
|
+
* })
|
|
318
|
+
*
|
|
319
|
+
* // cleanup .once listener before it fires
|
|
320
|
+
* listener()
|
|
321
|
+
* @param name - Name of event to listen to
|
|
322
|
+
* @param callback - function to fire on event
|
|
323
|
+
*/
|
|
324
|
+
type Once = (name: string, callback: (...params: any[]) => any) => DetachListeners;
|
|
325
|
+
/**
|
|
326
|
+
* Get data about user, activity, or context. Access sub-keys of state with `dot.prop` syntax.
|
|
327
|
+
* @example
|
|
328
|
+
* // Get the current state of analytics
|
|
329
|
+
* analytics.getState()
|
|
330
|
+
*
|
|
331
|
+
* // Get a subpath of state
|
|
332
|
+
* analytics.getState('context.offline')
|
|
333
|
+
* @param [key] - dot.prop.path value of state
|
|
334
|
+
*/
|
|
335
|
+
type GetState = (key?: string) => any;
|
|
336
|
+
/**
|
|
337
|
+
* Storage utilities for persisting data.
|
|
338
|
+
* These methods will allow you to save data in localStorage, cookies, or to the window.
|
|
339
|
+
* @example
|
|
340
|
+
* // Pull storage off analytics instance
|
|
341
|
+
* const { storage } = analytics
|
|
342
|
+
*
|
|
343
|
+
* // Get value
|
|
344
|
+
* storage.getItem('storage_key')
|
|
345
|
+
*
|
|
346
|
+
* // Set value
|
|
347
|
+
* storage.setItem('storage_key', 'value')
|
|
348
|
+
*
|
|
349
|
+
* // Remove value
|
|
350
|
+
* storage.removeItem('storage_key')
|
|
351
|
+
* @property getItem - Get value from storage
|
|
352
|
+
* @property setItem - Set storage value
|
|
353
|
+
* @property removeItem - Remove storage value
|
|
354
|
+
*/
|
|
355
|
+
type Storage = {
|
|
356
|
+
getItem: GetItem;
|
|
357
|
+
setItem: SetItem;
|
|
358
|
+
removeItem: RemoveItem;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Get value from storage
|
|
362
|
+
* @example
|
|
363
|
+
* analytics.storage.getItem('storage_key')
|
|
364
|
+
* @param key - storage key
|
|
365
|
+
* @param [options] - storage options
|
|
366
|
+
*/
|
|
367
|
+
type GetItem = (key: string, options?: any) => any;
|
|
368
|
+
/**
|
|
369
|
+
* Set storage value
|
|
370
|
+
* @example
|
|
371
|
+
* analytics.storage.setItem('storage_key', 'value')
|
|
372
|
+
* @param key - storage key
|
|
373
|
+
* @param value - storage value
|
|
374
|
+
* @param [options] - storage options
|
|
375
|
+
*/
|
|
376
|
+
type SetItem = (key: string, value: any, options?: any) => void;
|
|
377
|
+
/**
|
|
378
|
+
* Remove storage value
|
|
379
|
+
* @example
|
|
380
|
+
* analytics.storage.removeItem('storage_key')
|
|
381
|
+
* @param key - storage key
|
|
382
|
+
* @param [options] - storage options
|
|
383
|
+
*/
|
|
384
|
+
type RemoveItem = (key: string, options?: any) => void;
|
|
385
|
+
/**
|
|
386
|
+
* Async reduce over matched plugin methods
|
|
387
|
+
* Fires plugin functions
|
|
388
|
+
*/
|
|
389
|
+
function processEvent(): void;
|
|
390
|
+
/**
|
|
391
|
+
* Return array of event names
|
|
392
|
+
* @param eventType - original event type
|
|
393
|
+
* @param namespace - optional namespace postfix
|
|
394
|
+
* @returns - type, method, end
|
|
395
|
+
*/
|
|
396
|
+
function getEventNames(eventType: string, namespace: string): any[];
|
|
397
|
+
/**
|
|
398
|
+
* Generate arguments to pass to plugin methods
|
|
399
|
+
* @param instance - analytics instance
|
|
400
|
+
* @param abortablePlugins - plugins that can be cancelled by caller
|
|
401
|
+
* @returns function to inject plugin params
|
|
402
|
+
*/
|
|
403
|
+
function argumentFactory(instance: any, abortablePlugins: any[]): any;
|
|
404
|
+
/**
|
|
405
|
+
* Verify plugin is not calling itself with whatever:myPluginName self refs
|
|
406
|
+
*/
|
|
407
|
+
function validateMethod(): void;
|
|
408
|
+
/**
|
|
409
|
+
* Return the canonical URL and rmove the hash.
|
|
410
|
+
* @param search - search param
|
|
411
|
+
* @returns return current canonical URL
|
|
412
|
+
*/
|
|
413
|
+
function currentUrl(search: string): string;
|
|
414
|
+
/**
|
|
415
|
+
* Page data for overides
|
|
416
|
+
* @property [title] - Page title
|
|
417
|
+
* @property [url] - Page url
|
|
418
|
+
* @property [path] - Page path
|
|
419
|
+
* @property [search] - Page search
|
|
420
|
+
* @property [width] - Page width
|
|
421
|
+
* @property [height] - Page height
|
|
422
|
+
*/
|
|
423
|
+
interface PageDataBase {
|
|
424
|
+
title?: string;
|
|
425
|
+
url?: string;
|
|
426
|
+
path?: string;
|
|
427
|
+
search?: string;
|
|
428
|
+
width?: string;
|
|
429
|
+
height?: string;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Get information about current page
|
|
433
|
+
* @param [pageData = {}] - Page data overides
|
|
434
|
+
*/
|
|
435
|
+
type getPageData = (pageData?: PageData) => PageData;
|
|
436
|
+
/**
|
|
437
|
+
* @property name - Name of plugin
|
|
438
|
+
* @property [EVENTS] - exposed events of plugin
|
|
439
|
+
* @property [config] - Configuration of plugin
|
|
440
|
+
* @property [initialize] - Load analytics scripts method
|
|
441
|
+
* @property [page] - Page visit tracking method
|
|
442
|
+
* @property [track] - Custom event tracking method
|
|
443
|
+
* @property [identify] - User identify method
|
|
444
|
+
* @property [loaded] - Function to determine if analytics script loaded
|
|
445
|
+
* @property [ready] - Fire function when plugin ready
|
|
446
|
+
*/
|
|
447
|
+
interface AnalyticsPluginBase {
|
|
448
|
+
name: string;
|
|
449
|
+
EVENTS?: any;
|
|
450
|
+
config?: any;
|
|
451
|
+
initialize?: (...params: any[]) => any;
|
|
452
|
+
page?: (...params: any[]) => any;
|
|
453
|
+
track?: (...params: any[]) => any;
|
|
454
|
+
identify?: (...params: any[]) => any;
|
|
455
|
+
loaded?: (...params: any[]) => any;
|
|
456
|
+
ready?: (...params: any[]) => any;
|
|
457
|
+
}
|
|
458
|
+
export type PageData<T extends string = string> = PageDataBase & Record<T, unknown>;
|
|
459
|
+
export type AnalyticsPlugin<T extends string = string> = AnalyticsPluginBase & (string extends T ? Record<string, unknown> : Record<T, unknown> & Record<string, unknown>);
|
|
460
|
+
export const CONSTANTS: constants;
|
|
461
|
+
export const init: typeof analytics;
|
|
462
|
+
export const Analytics: typeof analytics;
|
|
463
|
+
export default analytics;
|
|
464
|
+
}
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/index.d.ts
|
|
467
|
+
interface RegisterCustomElementsOptions {
|
|
468
|
+
/** PrimeUIX preset to provide to custom elements. */
|
|
469
|
+
preset: Preset;
|
|
470
|
+
/** Keycloak instance to provide to custom elements. */
|
|
471
|
+
keycloak: Keycloak;
|
|
472
|
+
/** Analytics instance to provide to custom elements. */
|
|
473
|
+
analytics?: AnalyticsInstance$1 | null;
|
|
474
|
+
/** Base URI to access the Moser Labs API. */
|
|
475
|
+
apiUri?: string;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Call this function to register all provided custom elements at once passing
|
|
479
|
+
* the Keycloak instance to them.
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* import Labs from '@moser-inc/moser-labs-themes/labs';
|
|
484
|
+
* import Keycloak from 'keycloak-js';
|
|
485
|
+
* import { registerCustomElements } from '@moser-inc/moser-labs-custom-elements';
|
|
486
|
+
*
|
|
487
|
+
* const keycloak = new Keycloak('/keycloak.json');
|
|
488
|
+
*
|
|
489
|
+
* keycloak.init({ onLoad: 'login-required' }).then((isAuthenticated) => {
|
|
490
|
+
* if (!isAuthenticated) return;
|
|
491
|
+
*
|
|
492
|
+
* registerCustomElements({
|
|
493
|
+
* preset: Labs,
|
|
494
|
+
* keycloak,
|
|
495
|
+
* apiUri: 'https://www.moserlabs.app'
|
|
496
|
+
* });
|
|
497
|
+
* });
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* Use the custom elements anywhere in your application.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```html
|
|
504
|
+
* <labs-account></labs-account>
|
|
505
|
+
* <labs-app-switcher></labs-app-switcher>
|
|
506
|
+
* <labs-avatar></labs-avatar>
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
declare function registerCustomElements(options: RegisterCustomElementsOptions): void;
|
|
510
|
+
//#endregion
|
|
511
|
+
export { RegisterCustomElementsOptions, registerCustomElements };
|