@fingerru/vue 1.0.0 → 1.1.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/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { start as h } from "@fingerru/agent";
2
2
  import { inject as m, shallowRef as F, computed as a, onMounted as L } from "vue";
3
- const l = Symbol("fingprint"), y = (n) => {
4
- const s = h(n), o = {
3
+ const l = Symbol("fingprint"), w = (n) => {
4
+ const s = h(n, {
5
+ type: "vue",
6
+ version: "1.1.0"
7
+ }), o = {
5
8
  getVisitorData: (t) => s.get(t)
6
9
  };
7
10
  return {
@@ -14,7 +17,7 @@ const l = Symbol("fingprint"), y = (n) => {
14
17
  error: void 0,
15
18
  isFetched: !1,
16
19
  isLoading: !1
17
- }, V = {
20
+ }, y = {
18
21
  data: void 0,
19
22
  error: void 0,
20
23
  isFetched: !1,
@@ -31,7 +34,7 @@ const l = Symbol("fingprint"), y = (n) => {
31
34
  const e = F(D), u = a(() => e.value.data), g = a(() => e.value.error), f = a(() => e.value.isLoading), v = a(() => e.value.isFetched), d = (p) => {
32
35
  if (i)
33
36
  return i;
34
- e.value = V;
37
+ e.value = y;
35
38
  const r = t.getVisitorData({ timeout: s, ignoreCache: o, ...p });
36
39
  return i = r, r.then((c) => {
37
40
  e.value = {
@@ -63,7 +66,7 @@ const l = Symbol("fingprint"), y = (n) => {
63
66
  };
64
67
  };
65
68
  export {
66
- y as createFingprint,
69
+ w as createFingprint,
67
70
  x as useVisitorData
68
71
  };
69
72
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/config.ts","../src/plugin.ts","../src/use-visitor-data.ts"],"sourcesContent":["import type { GetOptions, VisitorResult } from '@fingerru/agent'\nimport { type InjectionKey } from 'vue'\n\nexport interface FingprintContextValue {\n getVisitorData: (config?: GetOptions) => Promise<VisitorResult>\n}\n\nexport const pluginKey: InjectionKey<FingprintContextValue> = Symbol('fingprint')\n","import { start, type GetOptions, type StartOptions } from '@fingerru/agent'\nimport type { App } from 'vue'\nimport { pluginKey, type FingprintContextValue } from './config'\n\nexport type CreateFingprintOptions = StartOptions\n\ndeclare module 'vue' {\n interface ComponentCustomProperties {\n $fingprint: FingprintContextValue\n }\n}\n\nexport const createFingprint = (options: CreateFingprintOptions) => {\n const agent = start(options)\n\n const client = {\n getVisitorData: (getOptions?: GetOptions) => agent.get(getOptions),\n }\n\n return {\n install: (app: App) => {\n app.provide(pluginKey, client)\n app.config.globalProperties.$fingprint = client\n },\n }\n}\n","import { computed, inject, onMounted, shallowRef, type ComputedRef } from 'vue'\nimport { pluginKey } from './config'\nimport type { GetOptions, VisitorResult } from '@fingerru/agent'\nimport type { QueryIdle, QueryLoading, QueryResult } from './types'\n\ninterface UseVisitorDataConfig {\n /**\n * Если `true`, автоматически запрашивает данные посетителя после монтирования\n * компонента. По умолчанию запрос выполняется только при явном вызове `getData()`.\n */\n immediate?: boolean\n}\n\nexport type QueryResultRefs<TData, TError = Error> = {\n [K in keyof QueryResult<TData, TError>]: ComputedRef<QueryResult<TData, TError>[K]>\n}\n\nexport type UseVisitorDataOptions = GetOptions & UseVisitorDataConfig\n\nexport type UseVisitorDataReturn = QueryResultRefs<VisitorResult> & {\n /**\n * Выполняет запрос на идентификацию к серверу и возвращает данные посетителя.\n */\n getData: (options?: GetOptions) => Promise<VisitorResult>\n}\n\nconst idle: QueryIdle = {\n data: undefined,\n error: undefined,\n isFetched: false,\n isLoading: false,\n}\n\nconst loading: QueryLoading = {\n data: undefined,\n error: undefined,\n isFetched: false,\n isLoading: true,\n}\n\nexport const useVisitorData = ({\n immediate,\n timeout,\n ignoreCache,\n}: UseVisitorDataOptions = {}): UseVisitorDataReturn => {\n const context = inject(pluginKey)\n\n if (!context) {\n throw new Error('useVisitorData must be used after app.use(createFingprint(...)).')\n }\n\n let pendingPromise: Promise<VisitorResult> | null = null\n const result = shallowRef<QueryResult<VisitorResult>>(idle)\n const data = computed(() => result.value.data)\n const error = computed(() => result.value.error)\n const isLoading = computed(() => result.value.isLoading)\n const isFetched = computed(() => result.value.isFetched)\n\n const getData = (overrideOptions?: GetOptions): Promise<VisitorResult> => {\n if (pendingPromise) {\n return pendingPromise\n }\n\n result.value = loading\n\n const request = context.getVisitorData({ timeout, ignoreCache, ...overrideOptions })\n\n pendingPromise = request\n\n request\n .then((visitor) => {\n result.value = {\n data: visitor,\n error: undefined,\n isFetched: true,\n isLoading: false,\n }\n })\n .catch((error) => {\n result.value = {\n data: undefined,\n error: error,\n isFetched: false,\n isLoading: false,\n }\n })\n .finally(() => {\n if (pendingPromise === request) {\n pendingPromise = null\n }\n })\n\n return request\n }\n\n onMounted(() => {\n if (immediate) {\n getData().catch(() => undefined)\n }\n })\n\n return {\n data,\n error,\n isLoading,\n isFetched,\n getData,\n }\n}\n"],"names":["pluginKey","createFingprint","options","agent","start","client","getOptions","app","idle","loading","useVisitorData","immediate","timeout","ignoreCache","context","inject","pendingPromise","result","shallowRef","data","computed","error","isLoading","isFetched","getData","overrideOptions","request","visitor","onMounted"],"mappings":";;AAOO,MAAMA,IAAiD,OAAO,WAAW,GCKnEC,IAAkB,CAACC,MAAoC;AAClE,QAAMC,IAAQC,EAAMF,CAAO,GAErBG,IAAS;AAAA,IACb,gBAAgB,CAACC,MAA4BH,EAAM,IAAIG,CAAU;AAAA,EAAA;AAGnE,SAAO;AAAA,IACL,SAAS,CAACC,MAAa;AACrB,MAAAA,EAAI,QAAQP,GAAWK,CAAM,GAC7BE,EAAI,OAAO,iBAAiB,aAAaF;AAAA,IAC3C;AAAA,EAAA;AAEJ,GCCMG,IAAkB;AAAA,EACtB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,WAAW;AAAA,EACX,WAAW;AACb,GAEMC,IAAwB;AAAA,EAC5B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,WAAW;AAAA,EACX,WAAW;AACb,GAEaC,IAAiB,CAAC;AAAA,EAC7B,WA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src/use-visitor-data.ts"],"sourcesContent":["import type { GetOptions, VisitorResult } from '@fingerru/agent'\nimport { type InjectionKey } from 'vue'\n\nexport interface FingprintContextValue {\n getVisitorData: (config?: GetOptions) => Promise<VisitorResult>\n}\n\nexport const pluginKey: InjectionKey<FingprintContextValue> = Symbol('fingprint')\n","import { start, type GetOptions, type StartOptions } from '@fingerru/agent'\nimport type { App } from 'vue'\nimport { pluginKey, type FingprintContextValue } from './config'\n\nexport type CreateFingprintOptions = StartOptions\n\ndeclare module 'vue' {\n interface ComponentCustomProperties {\n $fingprint: FingprintContextValue\n }\n}\n\nexport const createFingprint = (options: CreateFingprintOptions) => {\n const agent = start(options, {\n type: 'vue',\n version: __FINGPRINT_VUE_VERSION__,\n })\n\n const client = {\n getVisitorData: (getOptions?: GetOptions) => agent.get(getOptions),\n }\n\n return {\n install: (app: App) => {\n app.provide(pluginKey, client)\n app.config.globalProperties.$fingprint = client\n },\n }\n}\n","import { computed, inject, onMounted, shallowRef, type ComputedRef } from 'vue'\nimport { pluginKey } from './config'\nimport type { GetOptions, VisitorResult } from '@fingerru/agent'\nimport type { QueryIdle, QueryLoading, QueryResult } from './types'\n\ninterface UseVisitorDataConfig {\n /**\n * Если `true`, автоматически запрашивает данные посетителя после монтирования\n * компонента. По умолчанию запрос выполняется только при явном вызове `getData()`.\n */\n immediate?: boolean\n}\n\nexport type QueryResultRefs<TData, TError = Error> = {\n [K in keyof QueryResult<TData, TError>]: ComputedRef<QueryResult<TData, TError>[K]>\n}\n\nexport type UseVisitorDataOptions = GetOptions & UseVisitorDataConfig\n\nexport type UseVisitorDataReturn = QueryResultRefs<VisitorResult> & {\n /**\n * Выполняет запрос на идентификацию к серверу и возвращает данные посетителя.\n */\n getData: (options?: GetOptions) => Promise<VisitorResult>\n}\n\nconst idle: QueryIdle = {\n data: undefined,\n error: undefined,\n isFetched: false,\n isLoading: false,\n}\n\nconst loading: QueryLoading = {\n data: undefined,\n error: undefined,\n isFetched: false,\n isLoading: true,\n}\n\nexport const useVisitorData = ({\n immediate,\n timeout,\n ignoreCache,\n}: UseVisitorDataOptions = {}): UseVisitorDataReturn => {\n const context = inject(pluginKey)\n\n if (!context) {\n throw new Error('useVisitorData must be used after app.use(createFingprint(...)).')\n }\n\n let pendingPromise: Promise<VisitorResult> | null = null\n const result = shallowRef<QueryResult<VisitorResult>>(idle)\n const data = computed(() => result.value.data)\n const error = computed(() => result.value.error)\n const isLoading = computed(() => result.value.isLoading)\n const isFetched = computed(() => result.value.isFetched)\n\n const getData = (overrideOptions?: GetOptions): Promise<VisitorResult> => {\n if (pendingPromise) {\n return pendingPromise\n }\n\n result.value = loading\n\n const request = context.getVisitorData({ timeout, ignoreCache, ...overrideOptions })\n\n pendingPromise = request\n\n request\n .then((visitor) => {\n result.value = {\n data: visitor,\n error: undefined,\n isFetched: true,\n isLoading: false,\n }\n })\n .catch((error) => {\n result.value = {\n data: undefined,\n error: error,\n isFetched: false,\n isLoading: false,\n }\n })\n .finally(() => {\n if (pendingPromise === request) {\n pendingPromise = null\n }\n })\n\n return request\n }\n\n onMounted(() => {\n if (immediate) {\n getData().catch(() => undefined)\n }\n })\n\n return {\n data,\n error,\n isLoading,\n isFetched,\n getData,\n }\n}\n"],"names":["pluginKey","createFingprint","options","agent","start","client","getOptions","app","idle","loading","useVisitorData","immediate","timeout","ignoreCache","context","inject","pendingPromise","result","shallowRef","data","computed","error","isLoading","isFetched","getData","overrideOptions","request","visitor","onMounted"],"mappings":";;AAOO,MAAMA,IAAiD,OAAO,WAAW,GCKnEC,IAAkB,CAACC,MAAoC;AAClE,QAAMC,IAAQC,EAAMF,GAAS;AAAA,IAC3B,MAAM;AAAA,IACN,SAAS;AAAA,EAAA,CACV,GAEKG,IAAS;AAAA,IACb,gBAAgB,CAACC,MAA4BH,EAAM,IAAIG,CAAU;AAAA,EAAA;AAGnE,SAAO;AAAA,IACL,SAAS,CAACC,MAAa;AACrB,MAAAA,EAAI,QAAQP,GAAWK,CAAM,GAC7BE,EAAI,OA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A,SAAAE,EAAU,MAAM;AACd,IAAIjB,KACFa,EAAA,EAAU,MAAM,MAAA;AAAA,KAAe;AAAA,EAEnC,CAAC,GAEM;AAAA,IACL,MAAAL;AAAA,IACA,OAAAE;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,SAAAC;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fingerru/vue",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Vue SDK for the Fingprint service.",
5
5
  "keywords": [
6
6
  "browser",
@@ -32,7 +32,7 @@
32
32
  "LICENSE"
33
33
  ],
34
34
  "dependencies": {
35
- "@fingerru/agent": "1.0.0"
35
+ "@fingerru/agent": "1.1.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "vue": "^3.0.0",