@sweepbright/api-client 0.30.2 → 0.30.4
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/.circleci/config.yml +102 -0
- package/.devcontainer/Dockerfile +23 -0
- package/.devcontainer/devcontainer.json +59 -0
- package/.editorconfig +11 -0
- package/.eslintrc.json +6 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +40 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/jest.config.js +7 -0
- package/mockServer.ts +44 -0
- package/package.json +3 -6
- package/setupTests.ts +1 -0
- package/src/__tests__/auth.test.ts +14 -0
- package/src/__tests__/channels.test.ts +104 -0
- package/src/__tests__/contacts.test.ts +85 -0
- package/src/__tests__/estates.test.ts +50 -0
- package/src/__tests__/leads.test.ts +67 -0
- package/src/common/currencies.ts +50 -0
- package/src/common/types.ts +1 -0
- package/src/entities/office.ts +193 -0
- package/src/entities/property.ts +574 -0
- package/src/index.ts +128 -0
- package/src/resources/channel_accounts.ts +39 -0
- package/src/resources/channels.ts +52 -0
- package/src/resources/companies.ts +15 -0
- package/src/resources/contact_preferences.ts +14 -0
- package/src/resources/contacts.ts +38 -0
- package/src/resources/estates.ts +145 -0
- package/src/resources/leads.ts +65 -0
- package/src/resources/negotiators.ts +19 -0
- package/src/resources/offices.ts +12 -0
- package/src/types.ts +88 -0
- package/src/utils.ts +35 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ClientCtx, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function (ctx: ClientCtx) {
|
|
4
|
+
async function getAll({ companyId }: { companyId: string }) {
|
|
5
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
6
|
+
const endpoint = `/services/companies/${companyId}/channel-accounts`;
|
|
7
|
+
|
|
8
|
+
return ctx.httpClient.get(endpoint, {
|
|
9
|
+
params: {
|
|
10
|
+
includes: 'channel',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function get({ channelAccountId }: { channelAccountId: string }) {
|
|
16
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
17
|
+
const endpoint = `/services/channel-accounts/${channelAccountId}`;
|
|
18
|
+
|
|
19
|
+
return ctx.httpClient.get(endpoint, {
|
|
20
|
+
params: {
|
|
21
|
+
includes: 'channel',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function getEstateHash({
|
|
27
|
+
estateId,
|
|
28
|
+
channelAccountId,
|
|
29
|
+
}: {
|
|
30
|
+
estateId: string;
|
|
31
|
+
channelAccountId: string;
|
|
32
|
+
}): Promise<{ hash: string }> {
|
|
33
|
+
const endpoint = `services/estates/${estateId}/channel-accounts/${channelAccountId}/hash`;
|
|
34
|
+
const response = await ctx.httpClient.post(endpoint);
|
|
35
|
+
return response.data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { getAll, get, getEstateHash } as const;
|
|
39
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ClientCtx, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
interface ReferenceDetails {
|
|
4
|
+
reference_code: string;
|
|
5
|
+
estate_id: string;
|
|
6
|
+
channel_id: string;
|
|
7
|
+
channel_account_id: string;
|
|
8
|
+
company_id: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ChannelsResolveReferencesResult {
|
|
12
|
+
data: ReferenceDetails[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function (ctx: ClientCtx) {
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated use channels.resolveReferences()
|
|
18
|
+
*/
|
|
19
|
+
async function getPropertyIdFromReference(
|
|
20
|
+
channel: string,
|
|
21
|
+
referenceId: string
|
|
22
|
+
) {
|
|
23
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
24
|
+
const endpoint = `/channels/${channel}/channel-references/${referenceId}`;
|
|
25
|
+
|
|
26
|
+
return ctx.httpClient.get(endpoint);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param channel_id Channel ID, for example, `"immoweb"` or `"immovlan"` etc
|
|
31
|
+
* @param reference_code Reference
|
|
32
|
+
* @param company_id Company ID
|
|
33
|
+
*/
|
|
34
|
+
async function resolveReferences(
|
|
35
|
+
channel_id: string,
|
|
36
|
+
reference_code: string,
|
|
37
|
+
company_id?: string
|
|
38
|
+
): Promise<ChannelsResolveReferencesResult> {
|
|
39
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
40
|
+
const endpoint = `/services/channel-references`;
|
|
41
|
+
|
|
42
|
+
return ctx.httpClient.get(endpoint, {
|
|
43
|
+
params: {
|
|
44
|
+
channel_id,
|
|
45
|
+
reference_code,
|
|
46
|
+
company_id,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { getPropertyIdFromReference, resolveReferences };
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClientCtx, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function (ctx: ClientCtx) {
|
|
4
|
+
function get(attributes: { companyId: string; includes?: string[] }) {
|
|
5
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
6
|
+
|
|
7
|
+
return ctx.httpClient.get(`/companies/${attributes.companyId}`, {
|
|
8
|
+
params: {
|
|
9
|
+
includes: attributes.includes?.join(','),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return { get };
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClientCtx, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function contact_preferences(ctx: ClientCtx) {
|
|
4
|
+
function getAll(attributes: { contactId: string }) {
|
|
5
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
6
|
+
return ctx.httpClient.get(
|
|
7
|
+
`/services/contacts/${attributes.contactId}/preferences`
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
getAll,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ClientCtx, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function (ctx: ClientCtx) {
|
|
4
|
+
function getOne(attributes: { contactId: string }) {
|
|
5
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
6
|
+
return ctx.httpClient.get(`/services/contacts/${attributes.contactId}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getOneWithNegotiators(attributes: { contactId: string }) {
|
|
10
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
11
|
+
return ctx.httpClient.get(
|
|
12
|
+
`/services/contacts/${attributes.contactId}?includes=negotiators`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getAll(attributes: {
|
|
17
|
+
companyId: string;
|
|
18
|
+
page?: number;
|
|
19
|
+
limit?: number;
|
|
20
|
+
}) {
|
|
21
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
22
|
+
return ctx.httpClient.get(
|
|
23
|
+
`/services/companies/${attributes.companyId}/contacts`,
|
|
24
|
+
{
|
|
25
|
+
params: {
|
|
26
|
+
page: attributes.page ?? 1,
|
|
27
|
+
limit: attributes.limit ?? 10,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
getOne,
|
|
35
|
+
getOneWithNegotiators,
|
|
36
|
+
getAll,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Property } from '../entities/property';
|
|
2
|
+
import {
|
|
3
|
+
ClientCtx,
|
|
4
|
+
EstateInclude,
|
|
5
|
+
GetUnitsInput,
|
|
6
|
+
PropertiesOutput,
|
|
7
|
+
TokenType,
|
|
8
|
+
UnitsOutput,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
export default function (ctx: ClientCtx) {
|
|
12
|
+
function getOne(attributes: {
|
|
13
|
+
estateId: string;
|
|
14
|
+
companyId: string;
|
|
15
|
+
includes?: EstateInclude[];
|
|
16
|
+
}): Promise<Property> {
|
|
17
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
18
|
+
|
|
19
|
+
return ctx.httpClient
|
|
20
|
+
.get(`/services/estates/${attributes.estateId}`, {
|
|
21
|
+
params: {
|
|
22
|
+
includes: attributes.includes ?? [],
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
.then((res) => res.data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getAll(attributes: {
|
|
29
|
+
companyId: string;
|
|
30
|
+
page?: number;
|
|
31
|
+
limit?: number;
|
|
32
|
+
archived?: boolean;
|
|
33
|
+
}): Promise<PropertiesOutput> {
|
|
34
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
35
|
+
return ctx.httpClient.get(
|
|
36
|
+
`/services/companies/${attributes.companyId}/estates`,
|
|
37
|
+
{
|
|
38
|
+
params: {
|
|
39
|
+
page: attributes.page ?? 1,
|
|
40
|
+
limit: attributes.limit ?? 10,
|
|
41
|
+
archived: attributes.archived,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getUnits(
|
|
48
|
+
projectId: string,
|
|
49
|
+
{ page, limit, includes }: GetUnitsInput = {}
|
|
50
|
+
): Promise<UnitsOutput> {
|
|
51
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
52
|
+
return ctx.httpClient.get(`/services/projects/${projectId}/units`, {
|
|
53
|
+
params: {
|
|
54
|
+
page,
|
|
55
|
+
limit,
|
|
56
|
+
includes,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createPublication(attributes: {
|
|
62
|
+
estateId: string;
|
|
63
|
+
channelAccountId: string;
|
|
64
|
+
config: Record<string, any>;
|
|
65
|
+
}) {
|
|
66
|
+
ctx.checkAuth(TokenType.USER_TOKEN);
|
|
67
|
+
|
|
68
|
+
return ctx.httpClient.post(
|
|
69
|
+
`/estates/${attributes.estateId}/channel-accounts/${attributes.channelAccountId}/ads`,
|
|
70
|
+
{
|
|
71
|
+
config: attributes.config,
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function updatePublication(attributes: {
|
|
77
|
+
estateId: string;
|
|
78
|
+
channelAccountId: string;
|
|
79
|
+
config: Record<string, any>;
|
|
80
|
+
}) {
|
|
81
|
+
ctx.checkAuth(TokenType.USER_TOKEN);
|
|
82
|
+
|
|
83
|
+
return ctx.httpClient.put(
|
|
84
|
+
`/estates/${attributes.estateId}/channel-accounts/${attributes.channelAccountId}/ads`,
|
|
85
|
+
{
|
|
86
|
+
config: attributes.config,
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function unpublishPublication(attributes: {
|
|
92
|
+
estateId: string;
|
|
93
|
+
channelAccountId: string;
|
|
94
|
+
}) {
|
|
95
|
+
ctx.checkAuth(TokenType.USER_TOKEN);
|
|
96
|
+
|
|
97
|
+
return ctx.httpClient.delete(
|
|
98
|
+
`/estates/${attributes.estateId}/channel-accounts/${attributes.channelAccountId}/ads`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function scheduleVisit(
|
|
103
|
+
estateId: string,
|
|
104
|
+
attributes: {
|
|
105
|
+
first_name: string;
|
|
106
|
+
last_name: string;
|
|
107
|
+
email: string;
|
|
108
|
+
phone: string;
|
|
109
|
+
preferences?: {
|
|
110
|
+
locale: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
) {
|
|
114
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
115
|
+
|
|
116
|
+
return ctx.httpClient.put(
|
|
117
|
+
`/properties/${estateId}/schedule-visit`,
|
|
118
|
+
attributes
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function unstable_setPublicationUrl({
|
|
123
|
+
estateId,
|
|
124
|
+
url,
|
|
125
|
+
}: {
|
|
126
|
+
estateId: string;
|
|
127
|
+
url: string;
|
|
128
|
+
}) {
|
|
129
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
130
|
+
return ctx.httpClient.put(`/estates/${estateId}/website-url`, {
|
|
131
|
+
published_url: url,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
getOne,
|
|
137
|
+
getAll,
|
|
138
|
+
getUnits,
|
|
139
|
+
createPublication,
|
|
140
|
+
updatePublication,
|
|
141
|
+
unpublishPublication,
|
|
142
|
+
scheduleVisit,
|
|
143
|
+
unstable_setPublicationUrl,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ClientCtx, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function (ctx: ClientCtx) {
|
|
4
|
+
function createLead(attributes: {
|
|
5
|
+
firstName?: string;
|
|
6
|
+
lastName: string;
|
|
7
|
+
propertyId: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
phone?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
portal: string;
|
|
12
|
+
location_preference?: {
|
|
13
|
+
country: string;
|
|
14
|
+
postal_codes: string[];
|
|
15
|
+
};
|
|
16
|
+
}) {
|
|
17
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
18
|
+
|
|
19
|
+
const { firstName, lastName, propertyId, email, phone, message, portal } =
|
|
20
|
+
attributes;
|
|
21
|
+
|
|
22
|
+
return ctx.httpClient.put(`estates/${propertyId}/leads`, {
|
|
23
|
+
first_name: firstName,
|
|
24
|
+
last_name: lastName,
|
|
25
|
+
message,
|
|
26
|
+
email,
|
|
27
|
+
phone,
|
|
28
|
+
source_type: 'channel',
|
|
29
|
+
external_source: portal,
|
|
30
|
+
location_preference: attributes.location_preference,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function createUnassignedLead(
|
|
35
|
+
companyId: string,
|
|
36
|
+
attributes: {
|
|
37
|
+
first_name: string;
|
|
38
|
+
last_name: string;
|
|
39
|
+
phone: string;
|
|
40
|
+
email: string;
|
|
41
|
+
message: string;
|
|
42
|
+
source_type: 'channel';
|
|
43
|
+
external_source: string;
|
|
44
|
+
preferences?: {
|
|
45
|
+
types: string[];
|
|
46
|
+
negotiation: 'sale' | 'let';
|
|
47
|
+
condition: string;
|
|
48
|
+
min_price?: number;
|
|
49
|
+
max_price?: number;
|
|
50
|
+
wishes: string[];
|
|
51
|
+
min_rooms: number;
|
|
52
|
+
locale: string;
|
|
53
|
+
};
|
|
54
|
+
location_preference?: {
|
|
55
|
+
country: string;
|
|
56
|
+
postal_codes: string[];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
) {
|
|
60
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
61
|
+
return ctx.httpClient.put(`companies/${companyId}/leads`, attributes);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { createLead, createUnassignedLead };
|
|
65
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ClientCtx, NegotiatorInfo, TokenType } from '../types';
|
|
2
|
+
|
|
3
|
+
export default function (ctx: ClientCtx) {
|
|
4
|
+
function getNegotiatorsByIdCompanyId(attributes: {
|
|
5
|
+
ids: string;
|
|
6
|
+
companyId: string;
|
|
7
|
+
}) {
|
|
8
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
9
|
+
return ctx.httpClient.get(
|
|
10
|
+
`/services/companies/${attributes.companyId}/negotiators`,
|
|
11
|
+
{
|
|
12
|
+
params: { ids: attributes.ids },
|
|
13
|
+
}
|
|
14
|
+
) as unknown as Promise<{ data: NegotiatorInfo[] }>;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
getNegotiatorsByIdCompanyId,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OfficeData } from '../entities/office';
|
|
2
|
+
import { ClientCtx, TokenType } from '../types';
|
|
3
|
+
|
|
4
|
+
export default function (ctx: ClientCtx) {
|
|
5
|
+
function getOffice(attributes: { officeId: string }): Promise<OfficeData> {
|
|
6
|
+
ctx.checkAuth(TokenType.API_TOKEN);
|
|
7
|
+
|
|
8
|
+
return ctx.httpClient.get(`/service/offices/${attributes.officeId}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return { getOffice };
|
|
12
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Property } from './entities/property';
|
|
3
|
+
|
|
4
|
+
export enum Env {
|
|
5
|
+
PRODUCTION = 'production',
|
|
6
|
+
STAGING = 'staging',
|
|
7
|
+
DEV = 'dev',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum EstateInclude {
|
|
11
|
+
settings = 'settings',
|
|
12
|
+
channels = 'channels',
|
|
13
|
+
negotiator = 'negotiator',
|
|
14
|
+
'office.settings' = 'office.settings',
|
|
15
|
+
'project.settings' = 'project.settings',
|
|
16
|
+
'project.office.settings' = 'project.office.settings',
|
|
17
|
+
'project.properties.office.settings' = 'project.properties.office.settings',
|
|
18
|
+
'project.properties.settings' = 'project.properties.settings',
|
|
19
|
+
'properties.settings' = 'properties.settings',
|
|
20
|
+
'properties.office.settings' = 'properties.office.settings',
|
|
21
|
+
'properties.negotiator' = 'properties.negotiator',
|
|
22
|
+
'item.settings' = 'item.settings',
|
|
23
|
+
'item.office.settings' = 'item.office.settings',
|
|
24
|
+
'item.channels' = 'item.channels',
|
|
25
|
+
'item.project.settings' = 'item.project.settings',
|
|
26
|
+
'item.project.office.settings' = 'item.project.office.settings',
|
|
27
|
+
'item.project.properties.office.settings' = 'item.project.properties.office.settings',
|
|
28
|
+
'item.project.properties.settings' = 'item.project.properties.settings',
|
|
29
|
+
'item.properties.settings' = 'item.properties.settings',
|
|
30
|
+
'item.properties.office.settings' = 'item.properties.office.settings',
|
|
31
|
+
'item.negotiator' = 'item.negotiator',
|
|
32
|
+
'item.properties.negotiator' = 'item.properties.negotiator',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ClientConf = {
|
|
36
|
+
clientId?: string;
|
|
37
|
+
clientSecret?: string;
|
|
38
|
+
env?: Env;
|
|
39
|
+
version?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type InitConf = {
|
|
43
|
+
scopes?: string[];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export enum TokenType {
|
|
47
|
+
USER_TOKEN,
|
|
48
|
+
API_TOKEN,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type Auth = {
|
|
52
|
+
token: string;
|
|
53
|
+
expiresIn?: string;
|
|
54
|
+
type: TokenType;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type Maybe<T> = T | null;
|
|
58
|
+
|
|
59
|
+
export type ClientCtx = {
|
|
60
|
+
checkAuth: (tokenType: TokenType) => void;
|
|
61
|
+
httpClient: AxiosInstance;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export interface NegotiatorInfo {
|
|
65
|
+
id: number;
|
|
66
|
+
first_name?: string;
|
|
67
|
+
last_name?: string;
|
|
68
|
+
picture_url?: string;
|
|
69
|
+
full_name?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface GetUnitsInput {
|
|
73
|
+
page?: number;
|
|
74
|
+
limit?: number;
|
|
75
|
+
includes?: EstateInclude[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface UnitsOutput {
|
|
79
|
+
data: Property[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface PropertyOutput {
|
|
83
|
+
data: Property;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface PropertiesOutput {
|
|
87
|
+
data: Property[];
|
|
88
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function getData(response: any) {
|
|
2
|
+
return response.data;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function handleRequestFailure(exception: {
|
|
6
|
+
response?: {
|
|
7
|
+
status: number;
|
|
8
|
+
data: any;
|
|
9
|
+
};
|
|
10
|
+
}) {
|
|
11
|
+
if (exception.response) {
|
|
12
|
+
const {
|
|
13
|
+
response: { status, data },
|
|
14
|
+
} = exception;
|
|
15
|
+
|
|
16
|
+
const error: any = new Error(`${status}: ${JSON.stringify(data)}`);
|
|
17
|
+
// remove parts of the stack trace so the error message (codeframe) shows up
|
|
18
|
+
// at the code where the actual problem is.
|
|
19
|
+
error.stack = (error.stack || '')
|
|
20
|
+
.split('\n')
|
|
21
|
+
.filter(
|
|
22
|
+
(line: string) =>
|
|
23
|
+
!line.includes('at handleRequestFailure') &&
|
|
24
|
+
!line.includes('at processTicksAndRejections')
|
|
25
|
+
)
|
|
26
|
+
.join('\n');
|
|
27
|
+
|
|
28
|
+
error.status = status;
|
|
29
|
+
error.data = data;
|
|
30
|
+
|
|
31
|
+
return Promise.reject(error);
|
|
32
|
+
} else {
|
|
33
|
+
return Promise.reject(exception);
|
|
34
|
+
}
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@sweepbright/shared-configs-tsconfig/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"resolveJsonModule": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"src/**/*"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"node_modules",
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"mockServer.ts",
|
|
16
|
+
"setupTests.ts"
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
}
|