@fingerru/vue 1.0.0-next.4 → 1.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/LICENSE +21 -0
- package/README.md +35 -114
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Fingprint
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
# @fingerru/vue
|
|
2
2
|
|
|
3
|
-
Vue 3 SDK для
|
|
3
|
+
Vue 3 SDK для получения идентификатора посетителя сайта.
|
|
4
4
|
|
|
5
5
|
## Установка
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm i @fingerru/vue
|
|
8
|
+
npm i @fingerru/vue
|
|
9
9
|
# or
|
|
10
|
-
yarn add @fingerru/vue
|
|
10
|
+
yarn add @fingerru/vue
|
|
11
11
|
# or
|
|
12
|
-
pnpm add @fingerru/vue
|
|
12
|
+
pnpm add @fingerru/vue
|
|
13
13
|
# or
|
|
14
|
-
bun add @fingerru/vue
|
|
14
|
+
bun add @fingerru/vue
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Подключение
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Зарегистрируйте `createFingprint()` при создании приложения. Передайте публичный
|
|
22
|
-
ключ проекта в `apiKey`:
|
|
19
|
+
Зарегистрируйте плагин и передайте публичный ключ проекта:
|
|
23
20
|
|
|
24
21
|
```ts
|
|
25
22
|
import { createApp } from 'vue'
|
|
@@ -27,143 +24,67 @@ import { createFingprint } from '@fingerru/vue'
|
|
|
27
24
|
import App from './App.vue'
|
|
28
25
|
|
|
29
26
|
createApp(App)
|
|
30
|
-
.use(
|
|
31
|
-
createFingprint({
|
|
32
|
-
apiKey: 'pk_live_example',
|
|
33
|
-
}),
|
|
34
|
-
)
|
|
27
|
+
.use(createFingprint({ apiKey: 'pk_live_example' }))
|
|
35
28
|
.mount('#app')
|
|
36
29
|
```
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
своего CDN и `loadTimeout` для времени загрузки runtime.
|
|
40
|
-
|
|
41
|
-
### 2. Используйте `useVisitorData`
|
|
31
|
+
Для своего proxy передайте его origin в `endpoint`:
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
```ts
|
|
34
|
+
createFingprint({
|
|
35
|
+
apiKey: 'pk_live_example',
|
|
36
|
+
endpoint: 'https://metrics.example.com',
|
|
37
|
+
})
|
|
38
|
+
```
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
</script>
|
|
40
|
+
`loadTimeout` задаёт максимальное время ожидания загрузки в миллисекундах; по умолчанию — `10000`. Чтобы включить кеш, передайте `cache`:
|
|
51
41
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
```ts
|
|
43
|
+
createFingprint({
|
|
44
|
+
apiKey: 'pk_live_example',
|
|
45
|
+
cache: { storage: 'sessionStorage', duration: 3600 },
|
|
46
|
+
})
|
|
57
47
|
```
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
компонента. По умолчанию запрос запускается только после вызова `getData()`.
|
|
49
|
+
`storage` принимает `memory`, `sessionStorage` или `localStorage`; `duration` задаётся в секундах.
|
|
61
50
|
|
|
62
|
-
##
|
|
51
|
+
## Composition API
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
например при отправке формы:
|
|
53
|
+
`useVisitorData()` возвращает реактивные данные и состояние запроса. Передайте `immediate: true`, чтобы выполнить запрос после монтирования:
|
|
66
54
|
|
|
67
55
|
```vue
|
|
68
56
|
<script setup lang="ts">
|
|
69
57
|
import { useVisitorData } from '@fingerru/vue'
|
|
70
58
|
|
|
71
|
-
const {
|
|
72
|
-
|
|
73
|
-
async function handleSubmit() {
|
|
74
|
-
const visitor = await getData()
|
|
75
|
-
console.log(visitor.user)
|
|
76
|
-
}
|
|
59
|
+
const { data, error, isLoading } = useVisitorData({ immediate: true })
|
|
77
60
|
</script>
|
|
78
61
|
|
|
79
62
|
<template>
|
|
80
|
-
<
|
|
63
|
+
<p v-if="isLoading">Получаем данные…</p>
|
|
64
|
+
<p v-else-if="error">Не удалось получить данные: {{ error.message }}</p>
|
|
65
|
+
<p v-else>Visitor: {{ data?.user }}</p>
|
|
81
66
|
</template>
|
|
82
67
|
```
|
|
83
68
|
|
|
84
|
-
Для `useVisitorData()`
|
|
85
|
-
можно передать непосредственно в `getData()`.
|
|
86
|
-
|
|
87
|
-
## Кеширование
|
|
88
|
-
|
|
89
|
-
Кеширование выключено по умолчанию. Чтобы включить его, добавьте `cache` в
|
|
90
|
-
настройки плагина:
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
createFingprint({
|
|
94
|
-
apiKey: 'pk_live_example',
|
|
95
|
-
cache: {
|
|
96
|
-
storage: 'sessionStorage',
|
|
97
|
-
duration: 3600,
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
```
|
|
69
|
+
Без `immediate` вызовите `getData()` при действии пользователя. Для `useVisitorData()` и `getData()` доступны параметры `timeout` и `ignoreCache`.
|
|
101
70
|
|
|
102
71
|
## Options API
|
|
103
72
|
|
|
104
|
-
|
|
105
|
-
`this.$fingprint.getVisitorData()`:
|
|
73
|
+
После регистрации плагина вызовите `this.$fingprint.getVisitorData()`:
|
|
106
74
|
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
export default defineComponent({
|
|
112
|
-
methods: {
|
|
113
|
-
async getVisitorData() {
|
|
114
|
-
const visitor = await this.$fingprint.getVisitorData()
|
|
115
|
-
console.log(visitor.user)
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
})
|
|
119
|
-
</script>
|
|
75
|
+
```ts
|
|
76
|
+
const visitor = await this.$fingprint.getVisitorData({ timeout: 5_000 })
|
|
77
|
+
console.log(visitor.user)
|
|
120
78
|
```
|
|
121
79
|
|
|
122
80
|
## Nuxt
|
|
123
81
|
|
|
124
|
-
|
|
125
|
-
плагине `plugins/fingprint.client.ts`:
|
|
82
|
+
SDK работает только в браузере. Зарегистрируйте его в клиентском плагине, например `plugins/fingprint.client.ts`:
|
|
126
83
|
|
|
127
84
|
```ts
|
|
128
85
|
import { createFingprint } from '@fingerru/vue'
|
|
129
86
|
|
|
130
87
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
nuxtApp.vueApp.use(
|
|
134
|
-
createFingprint({
|
|
135
|
-
apiKey: config.public.fingprintApiKey,
|
|
136
|
-
}),
|
|
137
|
-
)
|
|
138
|
-
})
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
Передайте публичный ключ через runtime-конфигурацию:
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
export default defineNuxtConfig({
|
|
145
|
-
runtimeConfig: {
|
|
146
|
-
public: {
|
|
147
|
-
fingprintApiKey: process.env.FINGPRINT_API_KEY,
|
|
148
|
-
},
|
|
149
|
-
},
|
|
88
|
+
nuxtApp.vueApp.use(createFingprint({ apiKey: 'pk_live_example' }))
|
|
150
89
|
})
|
|
151
90
|
```
|
|
152
|
-
|
|
153
|
-
Используйте `useVisitorData()` в клиентском компоненте, например в
|
|
154
|
-
`components/VisitorData.client.vue`:
|
|
155
|
-
|
|
156
|
-
```vue
|
|
157
|
-
<script setup lang="ts">
|
|
158
|
-
import { useVisitorData } from '@fingerru/vue'
|
|
159
|
-
|
|
160
|
-
const { data, getData, isLoading } = useVisitorData()
|
|
161
|
-
</script>
|
|
162
|
-
|
|
163
|
-
<template>
|
|
164
|
-
<button :disabled="isLoading" @click="getData()">
|
|
165
|
-
Получить visitor
|
|
166
|
-
</button>
|
|
167
|
-
<p v-if="data">Visitor: {{ data.user }}</p>
|
|
168
|
-
</template>
|
|
169
|
-
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fingerru/vue",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Vue SDK for the Fingprint service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"LICENSE"
|
|
32
33
|
],
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@fingerru/agent": "1.0.0
|
|
35
|
+
"@fingerru/agent": "1.0.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"vue": "^3.0.0",
|