@voicenter-team/events-sdk 0.0.18 → 0.0.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.
@@ -1,6 +1,25 @@
1
1
  <template>
2
2
  <div>
3
- <p v-if="loading">
3
+ <Transition name="fade">
4
+ <div v-if="isOnline && showSuccessNotification" class="message message--success" key="success">
5
+ Connection established!
6
+ </div>
7
+ </Transition>
8
+
9
+ <Transition name="fade">
10
+ <p v-if="!isOnline" class="message message--error" key="error">
11
+ No connection
12
+ <div class="message-container">
13
+ <Transition name="attempt-to-connect" mode="out-in">
14
+ <span v-if="attemptToConnect" :key="attemptToConnect" class="message">
15
+ Trying to connect to {{ attemptToConnect }}
16
+ </span>
17
+ </Transition>
18
+ </div>
19
+ </p>
20
+ </Transition>
21
+
22
+ <p v-if="loading && isOnline">
4
23
  Loading...
5
24
  </p>
6
25
 
@@ -28,6 +47,9 @@ import {EventTypeData} from '@/types/events'
28
47
  import {LoginType} from "@/enum/auth.enum";
29
48
 
30
49
  /* Data */
50
+ const showSuccessNotification = ref(false)
51
+ const isOnline = ref(true)
52
+ const attemptToConnect = ref<string | undefined>(undefined)
31
53
  const token = ref('')
32
54
  const loading = ref(false)
33
55
  const loggedId = ref(false)
@@ -137,6 +159,22 @@ async function login() {
137
159
  }
138
160
  )
139
161
 
162
+ sdk.on(
163
+ EventsEnum.ONLINE_STATUS_EVENT,
164
+ ({ data }) => {
165
+ isOnline.value = data.isSocketConnected
166
+ attemptToConnect.value = data.attemptToConnect
167
+
168
+ if (data.isSocketConnected) {
169
+ showSuccessNotification.value = true
170
+
171
+ setTimeout(() => {
172
+ showSuccessNotification.value = false
173
+ }, 3000)
174
+ }
175
+ }
176
+ )
177
+
140
178
  sdk.on(
141
179
  '*',
142
180
  (data) => {
@@ -183,3 +221,75 @@ async function login() {
183
221
  )
184
222
  }
185
223
  </script>
224
+
225
+ <style>
226
+ .fade-enter-active,
227
+ .fade-leave-active {
228
+ transition: opacity 0.5s ease;
229
+ }
230
+
231
+ .fade-enter-from,
232
+ .fade-leave-to {
233
+ opacity: 0;
234
+ }
235
+
236
+
237
+ .message-container {
238
+ position: relative;
239
+ min-height: 50px; /* Adjust based on your content's typical size */
240
+ }
241
+
242
+ /* Enhanced transition handling for attempt-to-connect */
243
+ .attempt-to-connect-enter-active, .attempt-to-connect-leave-active {
244
+ transition: opacity 0.5s, transform 0.5s;
245
+ position: absolute;
246
+ width: 100%;
247
+ top: 0;
248
+ left: 0;
249
+ }
250
+
251
+ .attempt-to-connect-enter {
252
+ opacity: 0;
253
+ transform: translateY(20px);
254
+ }
255
+
256
+ .attempt-to-connect-leave-active {
257
+ opacity: 1;
258
+ }
259
+
260
+ .attempt-to-connect-leave-to {
261
+ opacity: 0;
262
+ transform: translateY(-20px);
263
+ }
264
+
265
+ .attempt-to-connect-enter-to, .attempt-to-connect-leave {
266
+ opacity: 1;
267
+ transform: translateY(0);
268
+ position: relative;
269
+ }
270
+ </style>
271
+
272
+ <style lang="scss" scoped>
273
+ .message {
274
+ border-radius: 24px;
275
+ font-size: 24px;
276
+ text-align: center;
277
+ padding: 8px 0;
278
+
279
+ &--error {
280
+ background-color: #a31c1c;
281
+ color: white;
282
+
283
+ span {
284
+ font-size: 16px;
285
+ margin-top: 16px;
286
+ display: block;
287
+ }
288
+ }
289
+
290
+ &--success {
291
+ background-color: #1ca31c;
292
+ color: white;
293
+ }
294
+ }
295
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicenter-team/events-sdk",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "",
5
5
  "main": "dist/voicenter-events-sdk.cjs.js",
6
6
  "jsdelivr": "dist/voicenter-events-sdk.umd.js",
@@ -44,6 +44,8 @@ class AuthClass{
44
44
  const isLoggedIn = await this.checkLoginStatus(this.storageKey)
45
45
 
46
46
  if (!isLoggedIn) {
47
+ StorageClass.clearSessionStorage()
48
+
47
49
  await this.userLoginFunction(payload, this.storageKey, options.loginType)
48
50
  }
49
51
  }
@@ -110,7 +110,7 @@ class EventsSdkClass{
110
110
  this.allListeners.forEach((callback) => callback(allEventData))
111
111
  }
112
112
 
113
- public connect (server: ServerParameter = ServerParameter.DEFAULT, skipLogin = false) {
113
+ public connect (server: ServerParameter = ServerParameter.DEFAULT) {
114
114
  let serverToConnect: Server | undefined
115
115
 
116
116
  if (server === ServerParameter.DEFAULT) {
@@ -136,11 +136,6 @@ class EventsSdkClass{
136
136
  this.socketIoClass.initSocketEvents()
137
137
 
138
138
  this.socketIoClass.initKeepAlive()
139
-
140
- // TODO: check if it is needed here
141
- if (skipLogin) {
142
- return
143
- }
144
139
  }
145
140
 
146
141
  public disconnect () {
@@ -50,6 +50,14 @@ export class SocketIoClass{
50
50
  // url
51
51
  // )
52
52
 
53
+ this.eventsSdkClass.emit(
54
+ EventsEnum.ONLINE_STATUS_EVENT,
55
+ {
56
+ isSocketConnected: false,
57
+ attemptToConnect: url
58
+ }
59
+ )
60
+
53
61
  const options: Partial<ManagerOptions & SocketOptions> = {
54
62
  reconnection: false,
55
63
  upgrade: false,
@@ -87,6 +95,10 @@ export class SocketIoClass{
87
95
  .on(EventsEnum.KEEP_ALIVE_RESPONSE, (data) => this.onKeepAliveResponse(data))
88
96
  .on(EventsEnum.CONNECT, () => this.onConnect())
89
97
  .on(EventsEnum.DISCONNECT, () => this.onDisconnect())
98
+ .on(EventsEnum.CONNECT_ERROR_EVENT, () => {
99
+ this.eventsSdkClass.emit(EventsEnum.ONLINE_STATUS_EVENT, { isSocketConnected: false })
100
+ this.eventsSdkClass.connect(ServerParameter.NEXT)
101
+ })
90
102
  }
91
103
  }
92
104
 
@@ -7,6 +7,7 @@ export enum EventsEnum {
7
7
  ALL_USERS_STATUS = 'AllUsersStatus',
8
8
  CONNECT = 'connect',
9
9
  DISCONNECT = 'disconnect',
10
+ CONNECT_ERROR_EVENT = 'connect_error',
10
11
  EXTENSION_EVENT = 'ExtensionEvent',
11
12
  KEEP_ALIVE = 'keepalive',
12
13
  KEEP_ALIVE_RESPONSE = 'keepaliveResponse',
@@ -98,6 +98,7 @@ export interface KeepAliveResponseEvent extends CommonEventProperties {
98
98
 
99
99
  export interface OnlineStatusEvent {
100
100
  isSocketConnected: boolean
101
+ attemptToConnect?: string
101
102
  }
102
103
 
103
104
  /**
@@ -1 +0,0 @@
1
- {"host":"localhost:3000","info":{"title":"admin-api","contact":{},"version":"0.01","description":"irst Alpha - Hope it will wok for yall :-)","termsOfService":""},"paths":{"/Account/List/":{"post":{"tags":["Account"],"security":[{"AdminAuthentication":["Admin"]}],"responses":{"200":{"schema":{"$ref":"#/definitions/AccountListResponse"},"description":"Status 200"},"400":{"schema":{"$ref":"#/definitions/Error"},"description":"Error Response"}},"parameters":[{"in":"body","name":"RequestBody","schema":{"$ref":"#/definitions/AccountListRequest"},"description":"Searching for Account that meets the query. multiple values are support. multiple selections in same feild will be treated as OR, multiple feilds will be searched with OR between them."}],"x-AuthType":["Admin"],"operationId":"AccountList","x-serviceID":3,"x-methodName":"List","x-serviceName":"Account"}},"/Account/Update/":{"post":{"tags":["Account"],"security":[{"AdminAuthentication":["Admin"]}],"responses":{"200":{"schema":{"$ref":"#/definitions/Response"},"description":"Status 200"},"400":{"schema":{"$ref":"#/definitions/Error"},"description":"Error Response"}},"parameters":[],"x-AuthType":["Admin"],"operationId":"AccountUpdate","x-serviceID":3,"x-methodName":"Update","x-serviceName":"Account"}}},"schemes":["https"],"swagger":"2.0","basePath":"/v1","consumes":["application/json"],"produces":["application/json"],"definitions":{"Error":{"type":"object","required":["Description","Status"],"properties":{"Status":{"type":"integer","example":400,"description":"Code of the Error"},"Description":{"type":"string","example":"Not found","description":"Textual description of the error"},"ReasonPhrase":{"type":"string","example":"ID not valid","description":"Specific reason for the error"}}},"Response":{"type":"object","required":["Description","ReasonPhrase","Status"],"properties":{"Status":{"type":"integer","example":200,"description":"Code of response"},"Description":{"type":"string","example":"OK","description":"Description of response"},"ReasonPhrase":{"type":"string","description":"Data of response"}}},"AccountAdd":{"type":"object","properties":{}},"ProviderAdd":{"type":"object","properties":{}},"ProviderDisable":{"type":"object","properties":{}},"ProvidersAddList":{"type":"object","properties":{}},"ProviderPrefixAdd":{"type":"object","properties":{}},"AccountListRequest":{"type":"object","properties":{}},"AccountListResponse":{"type":"object","properties":{}},"ProviderListResponse":{"type":"object","properties":{}},"ProviderPrefixUpdate":{"type":"object","properties":{}},"ProvidersDisableList":{"type":"object","properties":{}},"ProviderPrefixAddList":{"type":"object","properties":{}},"ProviderPrefixUpdateList":{"type":"object","properties":{}},"ProviderPrefixBulkRequest":{"type":"object","properties":{}},"ProviderPrefixBulkResponse":{"type":"object","properties":{}},"ProviderPrefixListResponse":{"type":"object","properties":{}},"ProviderPrefixUpdateResponse":{"type":"object","properties":{}}},"securityDefinitions":{}}
package/swagger/index.js DELETED
@@ -1,60 +0,0 @@
1
- import fs from 'fs'
2
- import fastify from 'fastify'
3
- import fastifySwagger from 'fastify-swagger'
4
- import openapiGlue from 'fastify-openapi-glue'
5
-
6
- const app = fastify()
7
-
8
- const start = async () => {
9
- try {
10
- if (!fs.existsSync('./generated/Swagger.json')) {
11
- console.log('Swagger.json file not generated. Try to run: npm run update')
12
-
13
- return
14
- }
15
-
16
- const swagger = JSON.parse(fs.readFileSync('./generated/Swagger.json').toString())
17
-
18
- const swaggerOptions = {
19
- routePrefix: '/documentation',
20
- exposeRoute: true,
21
- swagger: {
22
- ...swagger,
23
- schemes: [ 'https', 'http' ],
24
- securityDefinitions: {
25
- JWT: {
26
- type: 'apiKey',
27
- name: 'Authorization',
28
- in: 'header'
29
- }
30
- },
31
- security: [ { JWT: [] } ]
32
- },
33
- uiConfig: {
34
- docExpansion: 'full',
35
- deepLinking: false
36
- }
37
- }
38
-
39
- const openapiGlueOptions = {
40
- specification: './generated/Swagger.json',
41
- service: {},
42
- }
43
-
44
- app.register(fastifySwagger, swaggerOptions)
45
-
46
- app.register(openapiGlue, openapiGlueOptions)
47
-
48
- await app.listen({
49
- port: 3000
50
- })
51
-
52
- console.log('Server is running on port: 3000')
53
- } catch (err) {
54
- console.error('Error starting server:', err)
55
-
56
- process.exit(1)
57
- }
58
- }
59
-
60
- start()
@@ -1,21 +0,0 @@
1
- {
2
- "name": "swagger",
3
- "version": "1.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "update": "node scripts/update-swagger-json.js",
9
- "start": "node index.js"
10
- },
11
- "keywords": [],
12
- "author": "",
13
- "license": "ISC",
14
- "dependencies": {
15
- "@fastify/swagger": "^8.13.0",
16
- "@voicenter-team/mysql-dynamic-cluster": "^3.0.5",
17
- "fastify": "^3.19.1",
18
- "fastify-swagger": "^4.8.3",
19
- "fastify-openapi-glue": "git+https://github.com/VoicenterTeam/fastify-openapi-glue.git"
20
- }
21
- }
@@ -1,53 +0,0 @@
1
- import fs from 'fs'
2
- import mysql from '@voicenter-team/mysql-dynamic-cluster'
3
-
4
- const connection = mysql.createPoolCluster({
5
- clusterName: 'demo',
6
- hosts: [
7
- {
8
- host: '192.168.187.22',
9
- port: 3306,
10
- name: 'lab22',
11
- }
12
- ],
13
- // Configuration for all pools
14
- defaultPoolSettings: {
15
- user: 'api',
16
- password: 'SecretAPI35t478p3!!!',
17
- database: 'voicenter_core',
18
- docsDatabase: 'monitor_events_api_doc',
19
- charset: 'utf8mb4',
20
- port: 3313,
21
- // validators: [],
22
- // loadFactors: [],
23
- },
24
- })
25
-
26
- const pathToFile = 'generated/'
27
- const filename = 'Swagger.json'
28
- const fullPath = pathToFile + filename
29
-
30
- const generate = async () => {
31
- await connection.connect()
32
-
33
- const results = await connection.query('SELECT monitor_events_api_doc.FN_GetSwagger(0.01) as data')
34
-
35
- const targetResult = results[0].data
36
-
37
- console.log(targetResult)
38
-
39
- const targetResultString = JSON.stringify(targetResult)
40
-
41
- if (!fs.existsSync(pathToFile)) {
42
- fs.mkdirSync(pathToFile, { recursive: true })
43
- }
44
-
45
- fs.writeFile(fullPath, targetResultString, (err) => {
46
- if (err) throw err
47
- console.log('Swagger.json is updated!')
48
- })
49
-
50
- await connection.disconnect()
51
- }
52
-
53
- generate().then(data => console.log(data))