Skip to content

Commit

Permalink
Merge pull request #24 from QuickBlox/dev/v2.0.0-alpha.4
Browse files Browse the repository at this point in the history
Release v2.0.0-alpha.4
  • Loading branch information
andrii-khomutovskyi-qb authored Aug 23, 2023
2 parents 16dd838 + b27ada6 commit dd2ef7b
Show file tree
Hide file tree
Showing 81 changed files with 1,233 additions and 703 deletions.
9 changes: 5 additions & 4 deletions bin/initConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function getBaseConfiguration() {
const QB_SDK_CONFIG_ENDPOINT_CHAT = readline.question(`Enter QuickBlox Chat endpoint (optional):\n`, { defaultInput: QB_DEFAULT_CHAT_ENDPOINT })
const QB_SDK_CONFIG_ICE_SERVERS = readline.question(`Enter QuickBlox ICE servers in one line (optional):\n`) || []

const QB_ADMIN_EMAIL = readline.questionEMail(`Enter QuickBlox account owner email:\n`)
const QB_ADMIN_PASSWORD = readline.question(`Enter QuickBlox account owner password:\n`, { hideEchoBack: true })

const enableIntegrationAPI = readline.keyInYN(`Enable integration with your API?\n`) || false
const BEARER_TOKEN = enableIntegrationAPI ? readline.question(`Enter Bearer Token:\n`) : ''
const QB_ADMIN_EMAIL = enableIntegrationAPI ? readline.questionEMail(`Enter QuickBlox account owner email:\n`) : ''
const QB_ADMIN_PASSWORD = enableIntegrationAPI ? readline.question(`Enter QuickBlox account owner password:\n`, { hideEchoBack: true }) : ''

const enableOpenAI = readline.keyInYN(`Enable OpenAI?\n`) || false
const OPENAI_API_KEY = enableOpenAI ? readline.question(`Enter OpenAI API Key:\n`) : ''
Expand All @@ -53,20 +54,20 @@ function getBaseConfiguration() {
QB_SDK_CONFIG_ENDPOINT_API,
QB_SDK_CONFIG_ENDPOINT_CHAT,
QB_SDK_CONFIG_ICE_SERVERS,
BEARER_TOKEN,
QB_ADMIN_EMAIL,
QB_ADMIN_PASSWORD,
BEARER_TOKEN,
OPENAI_API_KEY,
AI_QUICK_ANSWER,
AI_SUGGEST_PROVIDER,
AI_RECORD_ANALYTICS,
ENABLE_REDUX_LOGGER,
CLIENT_APP_URL,
SERVER_APP_URL,
ENABLE_GUEST_CLIENT,
DEFAULT_LANGUAGE,
FILE_SIZE_LIMIT,
FILE_EXTENSIONS_WHITELIST,
ENABLE_GUEST_CLIENT,
}
}

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "q-consultation-lite",
"version": "1.2.4-plus",
"version": "2.0.0-alpha.4",
"license": "MIT",
"author": {
"name": "Injoit LTD",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "q-consultation-api",
"version": "1.2.4-plus",
"version": "2.0.0-alpha.4",
"license": "MIT",
"author": {
"name": "Injoit LTD",
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/constants/notificationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const DIALOG_NOTIFICATION = 'DIALOG'
export const APPOINTMENT_NOTIFICATION = 'APPOINTMENT'
export const CLOSE_SESSION_NOTIFICATION = 'CLOSE_SESSION'
8 changes: 4 additions & 4 deletions packages/api/src/models/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const Error = Type.Object(

export const MultipartFile = Type.Object(
{
buffer: Type.Any(),
filename: Type.String(),
encoding: Type.String(),
mimetype: Type.String(),
buffer: Type.Any({ description: 'Record buffer' }),
filename: Type.String({ description: 'Record filename' }),
encoding: Type.String({ description: 'Record encoding' }),
mimetype: Type.String({ description: 'Record mimetype' }),
},
{
title: 'File',
Expand Down
148 changes: 104 additions & 44 deletions packages/api/src/models/quickblox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Type } from '@sinclair/typebox'
import { DateISO } from './common'

export const QBUserId = Type.Integer({ title: 'User ID' })
export const QBUserId = Type.Integer({
title: 'User ID',
description:
'ID of the user. Generated automatically by the server after user creation',
})
export const QBDialogId = Type.String({
pattern: '^[a-z0-9]{24}$',
title: 'Dialog ID',
Expand All @@ -10,13 +14,21 @@ export const QBMessageId = Type.String({
pattern: '^[a-z0-9]{24}$',
title: 'Message ID',
})
export const QBCustomObjectId = Type.String({ pattern: '^[a-z0-9]{24}$' })
export const QBCustomObjectId = Type.String({
pattern: '^[a-z0-9]{24}$',
description:
'ID of the custom object. Generated automatically by the server after creation',
})

export const QBUser = Type.Object(
{
id: QBUserId,
full_name: Type.String(),
email: Type.String({ format: 'email' }),
full_name: Type.String({
description: "User's full name",
minLength: 3,
maxLength: 60,
}),
email: Type.String({ format: 'email', description: "User's email" }),
// login: Type.String(),
// phone: Type.String(),
created_at: DateISO,
Expand Down Expand Up @@ -45,9 +57,19 @@ export const QCProvider = Type.Intersect(
[
QBBaseUserData,
Type.Object({
profession: Type.String(),
description: Type.Optional(Type.String()),
language: Type.Optional(Type.String()),
profession: Type.String({
description: "User's profession",
}),
description: Type.Optional(
Type.String({
description: "Description of the user's profession",
}),
),
language: Type.Optional(
Type.String({
description: "User's language",
}),
),
}),
],
{ $id: 'QCProvider' },
Expand All @@ -60,13 +82,25 @@ export const QCClient = Type.Intersect(
birthdate: Type.String({
pattern: '^\\d{4}-\\d{2}-\\d{2}$',
title: 'Date',
description: "User's birthdate",
}),
gender: Type.Union([
Type.Literal('male', { title: 'Male' }),
Type.Literal('female', { title: 'Female' }),
]),
address: Type.Optional(Type.String()),
language: Type.Optional(Type.String()),
gender: Type.Union(
[
Type.Literal('male', { title: 'male' }),
Type.Literal('female', { title: 'female' }),
],
{ description: "User's gender" },
),
address: Type.Optional(
Type.String({
description: "User's address",
}),
),
language: Type.Optional(
Type.String({
description: "User's language",
}),
),
}),
],
{ $id: 'QCClient' },
Expand Down Expand Up @@ -122,34 +156,54 @@ export const QCAppointment = Type.Intersect(
QBCustomObject,
Type.Object({
_parent_id: Type.Null(),
priority: Type.Integer({ minimum: 0, maximum: 2 }),
priority: Type.Integer({
minimum: 0,
maximum: 2,
description: 'The priority of the appointment in the queue',
}),
client_id: QBUserId,
provider_id: QBUserId,
dialog_id: QBDialogId,
description: Type.String(),
notes: Type.Optional(Type.String()),
conclusion: Type.Optional(Type.String()),
date_end: Type.Optional(DateISO),
language: Type.Optional(Type.String()),
description: Type.String({
description: 'Description of the appointment',
}),
notes: Type.Union([Type.Null(), Type.String()], {
description: 'Notes for appointment',
}),
conclusion: Type.Union([Type.Null(), Type.String()], {
description: 'Conclusions for appointments',
}),
date_end: Type.Union([Type.Null(), DateISO], {
description: 'End date of the appointment',
}),
language: Type.Union([Type.Null(), Type.String()], {
description: 'Language of the appointment',
}),
}),
],
{ $id: 'QCAppointment' },
)

export const QCAppointmentSortKeys = Type.Union([
Type.Literal('_id', { title: '_id' }),
Type.Literal('created_at', { title: 'created_at' }),
Type.Literal('updated_at', { title: 'updated_at' }),
Type.Literal('priority', { title: 'priority' }),
Type.Literal('client_id', { title: 'client_id' }),
Type.Literal('provider_id', { title: 'provider_id' }),
Type.Literal('dialog_id', { title: 'dialog_id' }),
Type.Literal('description', { title: 'description' }),
Type.Literal('notes', { title: 'notes' }),
Type.Literal('conclusion', { title: 'conclusion' }),
Type.Literal('date_end', { title: 'date_end' }),
Type.Literal('language', { title: 'language' }),
])
export const QCAppointmentSortKeys = Type.Union(
[
Type.Literal('_id', { title: '_id' }),
Type.Literal('created_at', { title: 'created_at' }),
Type.Literal('updated_at', { title: 'updated_at' }),
Type.Literal('priority', { title: 'priority' }),
Type.Literal('client_id', { title: 'client_id' }),
Type.Literal('provider_id', { title: 'provider_id' }),
Type.Literal('dialog_id', { title: 'dialog_id' }),
Type.Literal('description', { title: 'description' }),
Type.Literal('notes', { title: 'notes' }),
Type.Literal('conclusion', { title: 'conclusion' }),
Type.Literal('date_end', { title: 'date_end' }),
Type.Literal('language', { title: 'language' }),
],
{
description:
'Returns appointments with sorting in ascending or descending order',
},
)

export const QCRecord = Type.Intersect(
[
Expand All @@ -173,14 +227,20 @@ export const QCRecord = Type.Intersect(
{ $id: 'QCRecord' },
)

export const QCRecordSortKeys = Type.Union([
Type.Literal('_id', { title: '_id' }),
Type.Literal('created_at', { title: 'created_at' }),
Type.Literal('updated_at', { title: 'updated_at' }),
Type.Literal('uid', { title: 'File uid' }),
Type.Literal('name', { title: 'File name' }),
Type.Literal('transcription', { title: 'transcription' }),
Type.Literal('summary', { title: 'summary' }),
Type.Literal('actions', { title: 'actions' }),
Type.Literal('appointment_id', { title: 'appointment_id' }),
])
export const QCRecordSortKeys = Type.Union(
[
Type.Literal('_id', { title: '_id' }),
Type.Literal('created_at', { title: 'created_at' }),
Type.Literal('updated_at', { title: 'updated_at' }),
Type.Literal('uid', { title: 'File uid' }),
Type.Literal('name', { title: 'File name' }),
Type.Literal('transcription', { title: 'transcription' }),
Type.Literal('summary', { title: 'summary' }),
Type.Literal('actions', { title: 'actions' }),
Type.Literal('appointment_id', { title: 'appointment_id' }),
],
{
description:
'Returns records with sorting in ascending or descending order',
},
)
8 changes: 4 additions & 4 deletions packages/api/src/plugins/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ function statusError(error: unknown): number {
return error.response.status
}

if ('statusCode' in error && typeof error.statusCode === 'number') {
return error.statusCode
if ('statusCode' in error && !Number.isNaN(error.statusCode)) {
return Number(error.statusCode)
}

if ('code' in error && typeof error.code === 'number') {
return error.code
if ('code' in error && !Number.isNaN(error.code)) {
return Number(error.code)
}
}

Expand Down
20 changes: 20 additions & 0 deletions packages/api/src/plugins/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import fp from 'fastify-plugin'

class State {
private data: Dictionary<any> = {}

set<T>(name: string, value: T) {
this.data[name] = value
}

get<T = any>(name: string): T | null {
return this.data[name] || null
}
}

export default fp(
async (fastify) => {
fastify.decorateReply('payload', null)
fastify.decorateRequest('state', new State())

fastify.addHook('onRequest', async (request) => {
request.state = new State()
})

fastify.addHook('preSerialization', async (request, reply, payload) => {
// eslint-disable-next-line no-param-reassign
Expand All @@ -13,6 +30,9 @@ export default fp(
)

declare module 'fastify' {
interface FastifyRequest {
state: State
}
interface FastifyReply {
payload: any
}
Expand Down
Loading

0 comments on commit dd2ef7b

Please sign in to comment.