@ht-sdks/events-sdk-js-browser 1.5.1 → 1.5.4

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.
Files changed (45) hide show
  1. package/README.md +38 -0
  2. package/dist/cjs/core/analytics/index.js.map +1 -1
  3. package/dist/cjs/core/arguments-resolver/index.js +1 -1
  4. package/dist/cjs/core/arguments-resolver/index.js.map +1 -1
  5. package/dist/cjs/core/stats/remote-metrics.js.map +1 -1
  6. package/dist/cjs/generated/version.js +1 -1
  7. package/dist/cjs/lib/priority-queue/persisted.js.map +1 -1
  8. package/dist/cjs/plugins/env-enrichment/index.js +1 -1
  9. package/dist/cjs/plugins/env-enrichment/index.js.map +1 -1
  10. package/dist/pkg/core/analytics/index.js.map +1 -1
  11. package/dist/pkg/core/arguments-resolver/index.js +1 -1
  12. package/dist/pkg/core/arguments-resolver/index.js.map +1 -1
  13. package/dist/pkg/core/stats/remote-metrics.js.map +1 -1
  14. package/dist/pkg/generated/version.js +1 -1
  15. package/dist/pkg/lib/priority-queue/persisted.js.map +1 -1
  16. package/dist/pkg/plugins/env-enrichment/index.js +1 -1
  17. package/dist/pkg/plugins/env-enrichment/index.js.map +1 -1
  18. package/dist/types/core/analytics/index.d.ts.map +1 -1
  19. package/dist/types/core/buffer/index.d.ts +1 -1
  20. package/dist/types/core/stats/remote-metrics.d.ts.map +1 -1
  21. package/dist/types/core/storage/cookieStorage.d.ts.map +1 -1
  22. package/dist/types/core/storage/localStorage.d.ts.map +1 -1
  23. package/dist/types/core/storage/memoryStorage.d.ts.map +1 -1
  24. package/dist/types/core/storage/types.d.ts +1 -1
  25. package/dist/types/core/storage/types.d.ts.map +1 -1
  26. package/dist/types/generated/version.d.ts +1 -1
  27. package/dist/types/lib/priority-queue/persisted.d.ts.map +1 -1
  28. package/dist/umd/events.min.js +1 -1
  29. package/dist/umd/events.min.js.map +1 -1
  30. package/dist/umd/index.js +1 -1
  31. package/dist/umd/index.js.map +1 -1
  32. package/package.json +4 -2
  33. package/src/core/analytics/index.ts +27 -24
  34. package/src/core/arguments-resolver/index.ts +4 -4
  35. package/src/core/buffer/index.ts +4 -4
  36. package/src/core/stats/remote-metrics.ts +8 -5
  37. package/src/core/storage/cookieStorage.ts +3 -3
  38. package/src/core/storage/localStorage.ts +3 -3
  39. package/src/core/storage/memoryStorage.ts +3 -3
  40. package/src/core/storage/types.ts +1 -1
  41. package/src/generated/version.ts +1 -1
  42. package/src/lib/bind-all.ts +1 -1
  43. package/src/lib/priority-queue/persisted.ts +9 -6
  44. package/src/plugins/env-enrichment/index.ts +1 -1
  45. package/src/test-helpers/browser-storage.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ht-sdks/events-sdk-js-browser",
3
- "version": "1.5.1",
3
+ "version": "1.5.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ht-sdks/events-sdk-js-mono",
@@ -36,7 +36,9 @@
36
36
  "clean": "rm -rf dist",
37
37
  "lint": "concurrently 'eslint .' 'tsc --noEmit'",
38
38
  "test": "jest",
39
- "size-limit": "size-limit"
39
+ "size-limit": "size-limit",
40
+ "serve": "node src/tester/dev-server.js",
41
+ "build:dev": "npm run clean && npm run build-prep && concurrently 'npm run umd' 'npm:pkg' 'npm:cjs'"
40
42
  },
41
43
  "size-limit": [
42
44
  {
@@ -638,31 +638,34 @@ export class Analytics
638
638
  console.warn(deprecationWarning)
639
639
  const integrations = this.queue.plugins
640
640
  .filter((plugin) => plugin.type === 'destination')
641
- .reduce((acc, plugin) => {
642
- const name = `${plugin.name
643
- .toLowerCase()
644
- .replace('.', '')
645
- .split(' ')
646
- .join('-')}Integration`
647
-
648
- // @ts-expect-error
649
- const integration = window[name] as
650
- | (LegacyIntegration & { Integration?: LegacyIntegration })
651
- | undefined
652
-
653
- if (!integration) {
641
+ .reduce(
642
+ (acc, plugin) => {
643
+ const name = `${plugin.name
644
+ .toLowerCase()
645
+ .replace('.', '')
646
+ .split(' ')
647
+ .join('-')}Integration`
648
+
649
+ // @ts-expect-error
650
+ const integration = window[name] as
651
+ | (LegacyIntegration & { Integration?: LegacyIntegration })
652
+ | undefined
653
+
654
+ if (!integration) {
655
+ return acc
656
+ }
657
+
658
+ const nested = integration.Integration // hack - Google Analytics function resides in the "Integration" field
659
+ if (nested) {
660
+ acc[plugin.name] = nested
661
+ return acc
662
+ }
663
+
664
+ acc[plugin.name] = integration as LegacyIntegration
654
665
  return acc
655
- }
656
-
657
- const nested = integration.Integration // hack - Google Analytics function resides in the "Integration" field
658
- if (nested) {
659
- acc[plugin.name] = nested
660
- return acc
661
- }
662
-
663
- acc[plugin.name] = integration as LegacyIntegration
664
- return acc
665
- }, {} as Record<string, LegacyIntegration>)
666
+ },
667
+ {} as Record<string, LegacyIntegration>
668
+ )
666
669
 
667
670
  return integrations
668
671
  }
@@ -34,10 +34,10 @@ export function resolveArguments(
34
34
  }
35
35
 
36
36
  const data = isPlainObject(eventName)
37
- ? eventName.properties ?? {}
37
+ ? (eventName.properties ?? {})
38
38
  : isPlainObject(properties)
39
- ? properties
40
- : {}
39
+ ? properties
40
+ : {}
41
41
 
42
42
  let opts: Options = {}
43
43
  if (!isFunction(options)) {
@@ -66,7 +66,7 @@ export function resolvePageArguments(
66
66
  string | null,
67
67
  EventProperties,
68
68
  Options,
69
- Callback | undefined
69
+ Callback | undefined,
70
70
  ] {
71
71
  let resolvedCategory: string | undefined | null = null
72
72
  let resolvedName: string | undefined | null = null
@@ -106,7 +106,7 @@ export const hasBufferedPageContextAsLastArg = (
106
106
  * Represents a buffered method call that occurred before initialization.
107
107
  */
108
108
  export class PreInitMethodCall<
109
- MethodName extends PreInitMethodName = PreInitMethodName
109
+ MethodName extends PreInitMethodName = PreInitMethodName,
110
110
  > {
111
111
  method: MethodName
112
112
  args: PreInitMethodParams<MethodName>
@@ -143,7 +143,7 @@ type ReturnTypeUnwrap<Fn> = Fn extends (...args: any[]) => infer ReturnT
143
143
  type MethodCallMap = Partial<Record<PreInitMethodName, PreInitMethodCall[]>>
144
144
 
145
145
  type SnippetWindowBufferedMethodCall<
146
- MethodName extends PreInitMethodName = PreInitMethodName
146
+ MethodName extends PreInitMethodName = PreInitMethodName,
147
147
  > = [MethodName, ...PreInitMethodParams<MethodName>]
148
148
 
149
149
  /**
@@ -290,7 +290,7 @@ export class AnalyticsBuffered
290
290
  | ((instance: [Analytics, Context]) => T1 | PromiseLike<T1>)
291
291
  | null
292
292
  | undefined,
293
- onrejected?: (reason: unknown) => T2 | PromiseLike<T2>
293
+ onrejected?: (reason: unknown) => T2 | PromiseLike<T2>,
294
294
  ]
295
295
  ) {
296
296
  return this._promise.then(...args)
@@ -301,7 +301,7 @@ export class AnalyticsBuffered
301
301
  onrejected?:
302
302
  | ((reason: any) => TResult | PromiseLike<TResult>)
303
303
  | undefined
304
- | null
304
+ | null,
305
305
  ]
306
306
  ) {
307
307
  return this._promise.catch(...args)
@@ -29,11 +29,14 @@ const createRemoteMetric = (
29
29
  tags: string[],
30
30
  versionType: 'web' | 'npm'
31
31
  ): RemoteMetric => {
32
- const formattedTags = tags.reduce((acc, t) => {
33
- const [k, v] = t.split(':')
34
- acc[k] = v
35
- return acc
36
- }, {} as Record<string, string>)
32
+ const formattedTags = tags.reduce(
33
+ (acc, t) => {
34
+ const [k, v] = t.split(':')
35
+ acc[k] = v
36
+ return acc
37
+ },
38
+ {} as Record<string, string>
39
+ )
37
40
 
38
41
  return {
39
42
  type: 'Counter',
@@ -15,9 +15,9 @@ export interface CookieOptions {
15
15
  /**
16
16
  * Data storage using browser cookies
17
17
  */
18
- export class CookieStorage<Data extends StorageObject = StorageObject>
19
- implements Store<Data>
20
- {
18
+ export class CookieStorage<
19
+ Data extends StorageObject = StorageObject,
20
+ > implements Store<Data> {
21
21
  static get defaults(): CookieOptions {
22
22
  return {
23
23
  maxage: ONE_YEAR,
@@ -3,9 +3,9 @@ import { StorageObject, Store } from './types'
3
3
  /**
4
4
  * Data storage using browser's localStorage
5
5
  */
6
- export class LocalStorage<Data extends StorageObject = StorageObject>
7
- implements Store<Data>
8
- {
6
+ export class LocalStorage<
7
+ Data extends StorageObject = StorageObject,
8
+ > implements Store<Data> {
9
9
  private localStorageWarning(key: keyof Data, state: 'full' | 'unavailable') {
10
10
  console.warn(`Unable to access ${key}, localStorage may be ${state}`)
11
11
  }
@@ -3,9 +3,9 @@ import { Store, StorageObject } from './types'
3
3
  /**
4
4
  * Data Storage using in memory object
5
5
  */
6
- export class MemoryStorage<Data extends StorageObject = StorageObject>
7
- implements Store<Data>
8
- {
6
+ export class MemoryStorage<
7
+ Data extends StorageObject = StorageObject,
8
+ > implements Store<Data> {
9
9
  private cache: Record<string, unknown> = {}
10
10
 
11
11
  get<K extends keyof Data>(key: K): Data[K] | null {
@@ -11,7 +11,7 @@ export const StoreType = {
11
11
  *
12
12
  * Convenience settings for storage systems that AJS includes support for
13
13
  */
14
- export type StoreType = typeof StoreType[keyof typeof StoreType]
14
+ export type StoreType = (typeof StoreType)[keyof typeof StoreType]
15
15
 
16
16
  export type StorageObject = Record<string, unknown>
17
17
 
@@ -1,2 +1,2 @@
1
1
  // This file is generated.
2
- export const version = '1.5.1'
2
+ export const version = '1.5.4'
@@ -1,6 +1,6 @@
1
1
  export default function bindAll<
2
2
  ObjType extends { [key: string]: any },
3
- KeyType extends keyof ObjType
3
+ KeyType extends keyof ObjType,
4
4
  >(obj: ObjType): ObjType {
5
5
  const proto = obj.constructor.prototype
6
6
  for (const key of Object.getOwnPropertyNames(proto)) {
@@ -27,12 +27,15 @@ function persistItems(key: string, items: Context[]): void {
27
27
  const existing = persisted(key)
28
28
  const all = [...items, ...existing]
29
29
 
30
- const merged = all.reduce((acc, item) => {
31
- return {
32
- ...acc,
33
- [item.id]: item,
34
- }
35
- }, {} as Record<string, Context>)
30
+ const merged = all.reduce(
31
+ (acc, item) => {
32
+ return {
33
+ ...acc,
34
+ [item.id]: item,
35
+ }
36
+ },
37
+ {} as Record<string, Context>
38
+ )
36
39
 
37
40
  loc.setItem(key, JSON.stringify(Object.values(merged)))
38
41
  }
@@ -64,7 +64,7 @@ export function utm(query: string): Campaign {
64
64
 
65
65
  return query.split('&').reduce((acc, str) => {
66
66
  const [k, v = ''] = str.split('=')
67
- if (k.includes('utm_') && k.length > 4) {
67
+ if (k.startsWith('utm_') && k.length > 4) {
68
68
  let utmParam = k.slice(4) as keyof Campaign
69
69
  if (utmParam === 'campaign') {
70
70
  utmParam = 'name'
@@ -28,7 +28,7 @@ export const clearAjsBrowserStorage = () => {
28
28
 
29
29
  export function getBrowserStorage<
30
30
  CookieNames extends string,
31
- LSKeys extends string
31
+ LSKeys extends string,
32
32
  >({
33
33
  cookieNames,
34
34
  localStorageKeys,