@webitel/api-services 0.1.53 → 0.1.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/api-services",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  import axios, { type CreateAxiosDefaults } from 'axios';
2
2
 
3
- interface GenerateInstanceOptions extends CreateAxiosDefaults {
3
+ export interface GenerateInstanceOptions extends CreateAxiosDefaults {
4
4
  interceptors?: {
5
5
  request?: Parameters<
6
6
  ReturnType<typeof axios.create>['interceptors']['request']['use']
@@ -0,0 +1,62 @@
1
+ import {
2
+ CatalogGetDialogsQueryParams,
3
+ getMessages,
4
+ } from '@webitel/api-services/gen';
5
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
6
+
7
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
8
+ import {
9
+ applyTransform,
10
+ merge,
11
+ notify,
12
+ sanitize,
13
+ snakeToCamel,
14
+ starToSearch,
15
+ } from '../../transformers';
16
+
17
+ const getDialogsList = async (params) => {
18
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
19
+ CatalogGetDialogsQueryParams,
20
+ );
21
+
22
+ const requestParams = applyTransform(params, [
23
+ merge(getDefaultGetParams()),
24
+ (params) => ({
25
+ ...params,
26
+ q: params.search,
27
+ }),
28
+ starToSearch('q'),
29
+ sanitize(fieldsToSend),
30
+ ]);
31
+
32
+ try {
33
+ const response = await getMessages().catalogGetDialogs(requestParams);
34
+ const { data, next } = applyTransform(response.data, [
35
+ merge(getDefaultGetListResponse()),
36
+ ]);
37
+ return {
38
+ items: applyTransform(data || [], [
39
+ snakeToCamel(),
40
+ ]),
41
+ next,
42
+ };
43
+ } catch (err) {
44
+ throw applyTransform(err, [
45
+ notify,
46
+ ]);
47
+ }
48
+ };
49
+
50
+ const getLookup = (params) =>
51
+ getDialogsList({
52
+ ...params,
53
+ fields: params.fields || [
54
+ 'id',
55
+ 'title',
56
+ ],
57
+ });
58
+
59
+ export const ChatDialogsAPI = {
60
+ getList: getDialogsList,
61
+ getLookup,
62
+ };
@@ -15,6 +15,7 @@ export * from './caseStatusConditions/caseStatusConditions';
15
15
  export * from './caseStatuses/caseStatuses';
16
16
  export * from './catalog/catalog';
17
17
  export * from './changelogs/changelogs';
18
+ export * from './chatDialogs/chatDialogs';
18
19
  export * from './chatGateways/chatGateways';
19
20
  export * from './communications/communications';
20
21
  export * from './configurations/configurations';
@@ -1,7 +1,7 @@
1
1
  import { objCamelToSnake } from '../../../utils/api/caseConverters';
2
2
 
3
3
  const camelToSnakeTransformer =
4
- (skipKeys = []) =>
4
+ (skipKeys: string[] = []) =>
5
5
  (obj) =>
6
6
  objCamelToSnake(obj, skipKeys);
7
7
  export default camelToSnakeTransformer;
@@ -12,7 +12,7 @@ const notifyTransformer = (notificationObject) => {
12
12
  so, create a callback which will send notification with params, passed to it
13
13
  */
14
14
  const callback = ({ type, text }) =>
15
- apiServicesConfig.eventBus.$emit('notification', {
15
+ apiServicesConfig.eventBus?.$emit('notification', {
16
16
  type,
17
17
  text,
18
18
  });
@@ -1,7 +1,7 @@
1
1
  import { objSnakeToCamel } from '../../../utils/api/caseConverters';
2
2
 
3
3
  const snakeToCamelTransformer =
4
- (skipKeys = []) =>
4
+ (skipKeys: string[] = []) =>
5
5
  (obj) =>
6
6
  objSnakeToCamel(obj, skipKeys);
7
7
  export default snakeToCamelTransformer;
@@ -4,8 +4,8 @@ import { messages } from '../locale';
4
4
  export type ApiServicesConfig = {
5
5
  eventBus?: {
6
6
  $emit: (event: string, payload: unknown) => unknown;
7
- };
8
- i18n?: I18n;
7
+ } | null;
8
+ i18n?: I18n | null;
9
9
  };
10
10
 
11
11
  export const config: ApiServicesConfig = {
@@ -17,9 +17,10 @@ export const setConfig = (conf: ApiServicesConfig) => {
17
17
  Object.assign(config, conf);
18
18
 
19
19
  // Automatically merge api-services locale messages into the provided i18n instance
20
- if (conf.i18n?.global) {
20
+ const i18n = conf.i18n;
21
+ if (i18n?.global) {
21
22
  Object.entries(messages).forEach(([locale, localeMessages]) => {
22
- conf.i18n.global.mergeLocaleMessage(locale, localeMessages);
23
+ i18n.global.mergeLocaleMessage(locale, localeMessages);
23
24
  });
24
25
  }
25
26
  };
@@ -4,5 +4,5 @@ export interface DownloadFileOptions {
4
4
  response: any;
5
5
  fileFormat: FileFormat;
6
6
  filename?: string;
7
- mimetype?: string;
7
+ mimetype?: string | null;
8
8
  }
@@ -62,14 +62,14 @@ const convertObject =
62
62
  return newObj;
63
63
  };
64
64
 
65
- export const objSnakeToCamel = (obj, skipKeys = []) => {
65
+ export const objSnakeToCamel = (obj, skipKeys: string[] = []) => {
66
66
  return convertObject({
67
67
  self: objSnakeToCamel,
68
68
  converter: snakeToCamel,
69
69
  })(obj, skipKeys);
70
70
  };
71
71
 
72
- export const objCamelToSnake = (obj, skipKeys = []) => {
72
+ export const objCamelToSnake = (obj, skipKeys: string[] = []) => {
73
73
  return convertObject({
74
74
  self: objCamelToSnake,
75
75
  converter: camelToSnake,
@@ -17,5 +17,5 @@ export const OAuthSchema = z.object<ZodShape<ApiOAuthService>>({
17
17
  value: z.string().optional(),
18
18
  }),
19
19
  )
20
- .min(1),
20
+ .optional(),
21
21
  });