kommo-aiatende-api 1.2.6 → 1.2.7
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.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +56 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -895,6 +895,15 @@ interface ListCustomField extends BaseCustomField {
|
|
|
895
895
|
}
|
|
896
896
|
interface ListEntityCustomFieldsResponse {
|
|
897
897
|
_total_items?: number;
|
|
898
|
+
_page?: number;
|
|
899
|
+
_links?: {
|
|
900
|
+
self?: {
|
|
901
|
+
href: string;
|
|
902
|
+
};
|
|
903
|
+
next?: {
|
|
904
|
+
href: string;
|
|
905
|
+
};
|
|
906
|
+
};
|
|
898
907
|
_embedded?: {
|
|
899
908
|
custom_fields?: EntityCustomField[];
|
|
900
909
|
};
|
|
@@ -982,6 +991,12 @@ interface CustomFieldGroup {
|
|
|
982
991
|
}
|
|
983
992
|
interface ListCustomFieldGroupsResponse {
|
|
984
993
|
_embedded?: {
|
|
994
|
+
/** A chave que o Kommo devolve. */
|
|
995
|
+
custom_field_groups?: CustomFieldGroup[];
|
|
996
|
+
/**
|
|
997
|
+
* @deprecated Nome errado usado até a 1.2.6 (o Kommo nunca devolveu esta chave). O SDK ainda
|
|
998
|
+
* preenche com a mesma lista; use `custom_field_groups`.
|
|
999
|
+
*/
|
|
985
1000
|
custom_fields_groups?: CustomFieldGroup[];
|
|
986
1001
|
};
|
|
987
1002
|
}
|
|
@@ -997,7 +1012,16 @@ interface UpdateCustomFieldGroupInput {
|
|
|
997
1012
|
}
|
|
998
1013
|
|
|
999
1014
|
declare class CustomFieldsResource extends BaseResource {
|
|
1000
|
-
|
|
1015
|
+
/**
|
|
1016
|
+
* Campos da entidade. O Kommo devolve no máximo 50 por página: sem `page`, percorre todas as
|
|
1017
|
+
* páginas e devolve a lista inteira (conta com mais de 50 campos perdia o resto). Com `page`,
|
|
1018
|
+
* só aquela página.
|
|
1019
|
+
*/
|
|
1020
|
+
listEntity(entityType: EntityType, params?: {
|
|
1021
|
+
page?: number;
|
|
1022
|
+
limit?: number;
|
|
1023
|
+
}): Promise<ListEntityCustomFieldsResponse>;
|
|
1024
|
+
private paginaDeCampos;
|
|
1001
1025
|
getEntityById(entityType: EntityType, id: number): Promise<EntityCustomField>;
|
|
1002
1026
|
createEntity(entityType: EntityType, items: CreateEntityCustomFieldInput | CreateEntityCustomFieldInput[]): Promise<ListEntityCustomFieldsResponse>;
|
|
1003
1027
|
updateEntity(entityType: EntityType, items: UpdateEntityCustomFieldInput | UpdateEntityCustomFieldInput[]): Promise<ListEntityCustomFieldsResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -895,6 +895,15 @@ interface ListCustomField extends BaseCustomField {
|
|
|
895
895
|
}
|
|
896
896
|
interface ListEntityCustomFieldsResponse {
|
|
897
897
|
_total_items?: number;
|
|
898
|
+
_page?: number;
|
|
899
|
+
_links?: {
|
|
900
|
+
self?: {
|
|
901
|
+
href: string;
|
|
902
|
+
};
|
|
903
|
+
next?: {
|
|
904
|
+
href: string;
|
|
905
|
+
};
|
|
906
|
+
};
|
|
898
907
|
_embedded?: {
|
|
899
908
|
custom_fields?: EntityCustomField[];
|
|
900
909
|
};
|
|
@@ -982,6 +991,12 @@ interface CustomFieldGroup {
|
|
|
982
991
|
}
|
|
983
992
|
interface ListCustomFieldGroupsResponse {
|
|
984
993
|
_embedded?: {
|
|
994
|
+
/** A chave que o Kommo devolve. */
|
|
995
|
+
custom_field_groups?: CustomFieldGroup[];
|
|
996
|
+
/**
|
|
997
|
+
* @deprecated Nome errado usado até a 1.2.6 (o Kommo nunca devolveu esta chave). O SDK ainda
|
|
998
|
+
* preenche com a mesma lista; use `custom_field_groups`.
|
|
999
|
+
*/
|
|
985
1000
|
custom_fields_groups?: CustomFieldGroup[];
|
|
986
1001
|
};
|
|
987
1002
|
}
|
|
@@ -997,7 +1012,16 @@ interface UpdateCustomFieldGroupInput {
|
|
|
997
1012
|
}
|
|
998
1013
|
|
|
999
1014
|
declare class CustomFieldsResource extends BaseResource {
|
|
1000
|
-
|
|
1015
|
+
/**
|
|
1016
|
+
* Campos da entidade. O Kommo devolve no máximo 50 por página: sem `page`, percorre todas as
|
|
1017
|
+
* páginas e devolve a lista inteira (conta com mais de 50 campos perdia o resto). Com `page`,
|
|
1018
|
+
* só aquela página.
|
|
1019
|
+
*/
|
|
1020
|
+
listEntity(entityType: EntityType, params?: {
|
|
1021
|
+
page?: number;
|
|
1022
|
+
limit?: number;
|
|
1023
|
+
}): Promise<ListEntityCustomFieldsResponse>;
|
|
1024
|
+
private paginaDeCampos;
|
|
1001
1025
|
getEntityById(entityType: EntityType, id: number): Promise<EntityCustomField>;
|
|
1002
1026
|
createEntity(entityType: EntityType, items: CreateEntityCustomFieldInput | CreateEntityCustomFieldInput[]): Promise<ListEntityCustomFieldsResponse>;
|
|
1003
1027
|
updateEntity(entityType: EntityType, items: UpdateEntityCustomFieldInput | UpdateEntityCustomFieldInput[]): Promise<ListEntityCustomFieldsResponse>;
|
package/dist/index.js
CHANGED
|
@@ -135,6 +135,15 @@ var BaseResource = class {
|
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
// src/utils/emptyList.ts
|
|
139
|
+
function listOrEmpty(response, key, page = 1) {
|
|
140
|
+
const data = response.data;
|
|
141
|
+
if (response.status === 204 || data === "" || data === null || data === void 0) {
|
|
142
|
+
return { _page: page, _embedded: { [key]: [] } };
|
|
143
|
+
}
|
|
144
|
+
return response.data;
|
|
145
|
+
}
|
|
146
|
+
|
|
138
147
|
// src/resources/leads/index.ts
|
|
139
148
|
var LeadsResource = class extends BaseResource {
|
|
140
149
|
async list(params) {
|
|
@@ -187,7 +196,7 @@ var LeadsResource = class extends BaseResource {
|
|
|
187
196
|
const query = import_qs.default.stringify(queryParams, { skipNulls: true, arrayFormat: "brackets" });
|
|
188
197
|
const qsStr = query ? `?${query}` : "";
|
|
189
198
|
const response = await this.client.get(`/api/v4/leads${qsStr}`);
|
|
190
|
-
return response
|
|
199
|
+
return listOrEmpty(response, "leads", params?.page ?? 1);
|
|
191
200
|
}
|
|
192
201
|
async getById(id, params) {
|
|
193
202
|
try {
|
|
@@ -234,7 +243,7 @@ var LeadsResource = class extends BaseResource {
|
|
|
234
243
|
}
|
|
235
244
|
async listLossReasons() {
|
|
236
245
|
const response = await this.client.get("/api/v4/leads/loss_reasons");
|
|
237
|
-
return response
|
|
246
|
+
return listOrEmpty(response, "loss_reasons");
|
|
238
247
|
}
|
|
239
248
|
async getLossReasonById(id) {
|
|
240
249
|
const response = await this.client.get(`/api/v4/leads/loss_reasons/${id}`);
|
|
@@ -289,7 +298,7 @@ var ContactsResource = class extends BaseResource {
|
|
|
289
298
|
const query = import_qs2.default.stringify(queryParams, { skipNulls: true, arrayFormat: "brackets" });
|
|
290
299
|
const qsStr = query ? `?${query}` : "";
|
|
291
300
|
const response = await this.client.get(`/api/v4/contacts${qsStr}`);
|
|
292
|
-
return response
|
|
301
|
+
return listOrEmpty(response, "contacts", params?.page ?? 1);
|
|
293
302
|
}
|
|
294
303
|
async getById(id, params) {
|
|
295
304
|
try {
|
|
@@ -371,7 +380,7 @@ var TasksResource = class extends BaseResource {
|
|
|
371
380
|
const query = import_qs3.default.stringify(queryParams, { skipNulls: true, arrayFormat: "brackets" });
|
|
372
381
|
const qsStr = query ? `?${query}` : "";
|
|
373
382
|
const response = await this.client.get(`/api/v4/tasks${qsStr}`);
|
|
374
|
-
return response
|
|
383
|
+
return listOrEmpty(response, "tasks", params?.page ?? 1);
|
|
375
384
|
}
|
|
376
385
|
async getById(id) {
|
|
377
386
|
const response = await this.client.get(`/api/v4/tasks/${id}`);
|
|
@@ -435,7 +444,7 @@ var NotesResource = class extends BaseResource {
|
|
|
435
444
|
const response = await this.client.get(
|
|
436
445
|
`/api/v4/${normalType}/${entityId}/notes${qsStr}`
|
|
437
446
|
);
|
|
438
|
-
return response
|
|
447
|
+
return listOrEmpty(response, "notes");
|
|
439
448
|
}
|
|
440
449
|
async listByEntityType(entityType, params) {
|
|
441
450
|
const normalType = this.normalizeEntityType(entityType);
|
|
@@ -468,7 +477,7 @@ var NotesResource = class extends BaseResource {
|
|
|
468
477
|
const response = await this.client.get(
|
|
469
478
|
`/api/v4/${normalType}/notes${qsStr}`
|
|
470
479
|
);
|
|
471
|
-
return response
|
|
480
|
+
return listOrEmpty(response, "notes");
|
|
472
481
|
}
|
|
473
482
|
async getById(entityType, id) {
|
|
474
483
|
const normalType = this.normalizeEntityType(entityType);
|
|
@@ -512,13 +521,32 @@ var NotesResource = class extends BaseResource {
|
|
|
512
521
|
};
|
|
513
522
|
|
|
514
523
|
// src/resources/custom-fields/index.ts
|
|
524
|
+
var LIMITE_DE_CAMPOS = 50;
|
|
525
|
+
var MAX_PAGINAS_DE_CAMPOS = 40;
|
|
515
526
|
var CustomFieldsResource = class extends BaseResource {
|
|
516
527
|
// ==== CAMPOS DE ENTIDADES ====
|
|
517
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Campos da entidade. O Kommo devolve no máximo 50 por página: sem `page`, percorre todas as
|
|
530
|
+
* páginas e devolve a lista inteira (conta com mais de 50 campos perdia o resto). Com `page`,
|
|
531
|
+
* só aquela página.
|
|
532
|
+
*/
|
|
533
|
+
async listEntity(entityType, params) {
|
|
534
|
+
if (params?.page !== void 0)
|
|
535
|
+
return this.paginaDeCampos(entityType, params.page, params.limit);
|
|
536
|
+
const campos = [];
|
|
537
|
+
for (let page = 1; page <= MAX_PAGINAS_DE_CAMPOS; page++) {
|
|
538
|
+
const r = await this.paginaDeCampos(entityType, page, LIMITE_DE_CAMPOS);
|
|
539
|
+
const lista = r._embedded?.custom_fields ?? [];
|
|
540
|
+
campos.push(...lista);
|
|
541
|
+
if (lista.length < LIMITE_DE_CAMPOS) break;
|
|
542
|
+
}
|
|
543
|
+
return { _total_items: campos.length, _embedded: { custom_fields: campos } };
|
|
544
|
+
}
|
|
545
|
+
async paginaDeCampos(entityType, page, limit = LIMITE_DE_CAMPOS) {
|
|
518
546
|
const response = await this.client.get(
|
|
519
|
-
`/api/v4/${entityType}/custom_fields`
|
|
547
|
+
`/api/v4/${entityType}/custom_fields?page=${page}&limit=${limit}`
|
|
520
548
|
);
|
|
521
|
-
return response
|
|
549
|
+
return listOrEmpty(response, "custom_fields", page);
|
|
522
550
|
}
|
|
523
551
|
async getEntityById(entityType, id) {
|
|
524
552
|
const response = await this.client.get(
|
|
@@ -557,7 +585,7 @@ var CustomFieldsResource = class extends BaseResource {
|
|
|
557
585
|
const response = await this.client.get(
|
|
558
586
|
`/api/v4/catalogs/${listId}/custom_fields`
|
|
559
587
|
);
|
|
560
|
-
return response
|
|
588
|
+
return listOrEmpty(response, "custom_fields");
|
|
561
589
|
}
|
|
562
590
|
async getListById(listId, customFieldId) {
|
|
563
591
|
const response = await this.client.get(
|
|
@@ -592,12 +620,19 @@ var CustomFieldsResource = class extends BaseResource {
|
|
|
592
620
|
await this.client.delete(`/api/v4/catalogs/${listId}/custom_fields/${id}`);
|
|
593
621
|
}
|
|
594
622
|
};
|
|
623
|
+
function comGrupos(r) {
|
|
624
|
+
const grupos = r._embedded?.custom_field_groups ?? r._embedded?.custom_fields_groups ?? [];
|
|
625
|
+
return {
|
|
626
|
+
...r,
|
|
627
|
+
_embedded: { ...r._embedded, custom_field_groups: grupos, custom_fields_groups: grupos }
|
|
628
|
+
};
|
|
629
|
+
}
|
|
595
630
|
var CustomFieldGroupsResource = class extends BaseResource {
|
|
596
631
|
async list(entityType) {
|
|
597
632
|
const response = await this.client.get(
|
|
598
633
|
`/api/v4/${entityType}/custom_fields/groups`
|
|
599
634
|
);
|
|
600
|
-
return response
|
|
635
|
+
return comGrupos(listOrEmpty(response, "custom_field_groups"));
|
|
601
636
|
}
|
|
602
637
|
async getById(entityType, id) {
|
|
603
638
|
const response = await this.client.get(
|
|
@@ -611,7 +646,7 @@ var CustomFieldGroupsResource = class extends BaseResource {
|
|
|
611
646
|
`/api/v4/${entityType}/custom_fields/groups`,
|
|
612
647
|
payload
|
|
613
648
|
);
|
|
614
|
-
return response.data;
|
|
649
|
+
return comGrupos(response.data);
|
|
615
650
|
}
|
|
616
651
|
async update(entityType, id, payload) {
|
|
617
652
|
const response = await this.client.patch(
|
|
@@ -721,7 +756,7 @@ var PipelinesResource = class extends BaseResource {
|
|
|
721
756
|
// PIPELINES
|
|
722
757
|
async list() {
|
|
723
758
|
const response = await this.client.get("/api/v4/leads/pipelines");
|
|
724
|
-
return response
|
|
759
|
+
return listOrEmpty(response, "pipelines");
|
|
725
760
|
}
|
|
726
761
|
async getById(id) {
|
|
727
762
|
const response = await this.client.get(`/api/v4/leads/pipelines/${id}`);
|
|
@@ -749,7 +784,7 @@ var PipelinesResource = class extends BaseResource {
|
|
|
749
784
|
const response = await this.client.get(
|
|
750
785
|
`/api/v4/leads/pipelines/${pipelineId}/statuses${qsStr}`
|
|
751
786
|
);
|
|
752
|
-
return response
|
|
787
|
+
return listOrEmpty(response, "statuses");
|
|
753
788
|
}
|
|
754
789
|
async getStatusById(pipelineId, id, params) {
|
|
755
790
|
const query = import_qs6.default.stringify({ with: params?.with }, { skipNulls: true });
|
|
@@ -844,7 +879,7 @@ var CompaniesResource = class extends BaseResource {
|
|
|
844
879
|
const query = import_qs7.default.stringify(queryParams, { skipNulls: true, arrayFormat: "brackets" });
|
|
845
880
|
const qsStr = query ? `?${query}` : "";
|
|
846
881
|
const response = await this.client.get(`/api/v4/companies${qsStr}`);
|
|
847
|
-
return response
|
|
882
|
+
return listOrEmpty(response, "companies", params?.page ?? 1);
|
|
848
883
|
}
|
|
849
884
|
async getById(id, params) {
|
|
850
885
|
try {
|
|
@@ -895,7 +930,7 @@ var CatalogsResource = class extends BaseResource {
|
|
|
895
930
|
const query = import_qs8.default.stringify({ page: params?.page, limit: params?.limit }, { skipNulls: true });
|
|
896
931
|
const qsStr = query ? `?${query}` : "";
|
|
897
932
|
const response = await this.client.get(`/api/v4/catalogs${qsStr}`);
|
|
898
|
-
return response
|
|
933
|
+
return listOrEmpty(response, "catalogs", params?.page ?? 1);
|
|
899
934
|
}
|
|
900
935
|
async getById(id) {
|
|
901
936
|
const response = await this.client.get(`/api/v4/catalogs/${id}`);
|
|
@@ -933,7 +968,7 @@ var CatalogsResource = class extends BaseResource {
|
|
|
933
968
|
const response = await this.client.get(
|
|
934
969
|
`/api/v4/catalogs/${listId}/elements${qsStr}`
|
|
935
970
|
);
|
|
936
|
-
return response
|
|
971
|
+
return listOrEmpty(response, "elements");
|
|
937
972
|
}
|
|
938
973
|
async getElementById(listId, elementId) {
|
|
939
974
|
const response = await this.client.get(
|
|
@@ -980,7 +1015,7 @@ var UsersResource = class extends BaseResource {
|
|
|
980
1015
|
const query = import_qs9.default.stringify(queryParams, { skipNulls: true });
|
|
981
1016
|
const qsStr = query ? `?${query}` : "";
|
|
982
1017
|
const response = await this.client.get(`/api/v4/users${qsStr}`);
|
|
983
|
-
return response
|
|
1018
|
+
return listOrEmpty(response, "users", params?.page ?? 1);
|
|
984
1019
|
}
|
|
985
1020
|
async getById(id, params) {
|
|
986
1021
|
const queryParams = {};
|
|
@@ -1010,7 +1045,7 @@ var RolesResource = class extends BaseResource {
|
|
|
1010
1045
|
const query = import_qs9.default.stringify(queryParams, { skipNulls: true });
|
|
1011
1046
|
const qsStr = query ? `?${query}` : "";
|
|
1012
1047
|
const response = await this.client.get(`/api/v4/roles${qsStr}`);
|
|
1013
|
-
return response
|
|
1048
|
+
return listOrEmpty(response, "roles");
|
|
1014
1049
|
}
|
|
1015
1050
|
async getById(id, params) {
|
|
1016
1051
|
const queryParams = {};
|
|
@@ -1077,7 +1112,7 @@ var EventsResource = class extends BaseResource {
|
|
|
1077
1112
|
const query = import_qs10.default.stringify(queryParams, { skipNulls: true, arrayFormat: "brackets" });
|
|
1078
1113
|
const qsStr = query ? `?${query}` : "";
|
|
1079
1114
|
const response = await this.client.get(`/api/v4/events${qsStr}`);
|
|
1080
|
-
return response
|
|
1115
|
+
return listOrEmpty(response, "events", params?.page ?? 1);
|
|
1081
1116
|
}
|
|
1082
1117
|
async getById(id, params) {
|
|
1083
1118
|
const queryParams = {};
|
|
@@ -1097,7 +1132,7 @@ var EventsResource = class extends BaseResource {
|
|
|
1097
1132
|
const query = import_qs10.default.stringify(queryParams, { skipNulls: true });
|
|
1098
1133
|
const qsStr = query ? `?${query}` : "";
|
|
1099
1134
|
const response = await this.client.get(`/api/v4/events/types${qsStr}`);
|
|
1100
|
-
return response
|
|
1135
|
+
return listOrEmpty(response, "events_types");
|
|
1101
1136
|
}
|
|
1102
1137
|
};
|
|
1103
1138
|
|