@justins-home/api-services 1.1.0 → 1.1.1
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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +6 -0
- package/dist/index.js +32 -6
- package/dist/index.mjs +32 -6
- package/package.json +3 -3
- package/src/api-client.ts +45 -6
- package/src/authService.ts +0 -11
- package/src/inspectionService.ts +0 -8
- package/src/listingService.ts +0 -12
- package/src/maintenanceService.ts +0 -8
- package/src/notificationService.ts +0 -8
- package/src/tenancyService.ts +0 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
WARN Issue while reading "/home/runner/work/justins-home-platform-ui/justins-home-platform-ui/.npmrc". Failed to replace env in config: ${NODE_AUTH_TOKEN}
|
|
2
2
|
|
|
3
|
-
> @justins-home/api-services@1.1.
|
|
3
|
+
> @justins-home/api-services@1.1.1 build /home/runner/work/justins-home-platform-ui/justins-home-platform-ui/packages/api-services
|
|
4
4
|
> tsup src/index.ts --format esm,cjs
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[34mCLI[39m Target: node16
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m24.05 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 70ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m25.62 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 72ms
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -45,16 +45,42 @@ module.exports = __toCommonJS(index_exports);
|
|
|
45
45
|
|
|
46
46
|
// src/api-client.ts
|
|
47
47
|
var import_http_client = require("@justins-home/http-client");
|
|
48
|
+
function normalizeError(error) {
|
|
49
|
+
const response = error == null ? void 0 : error.response;
|
|
50
|
+
if (!response) {
|
|
51
|
+
throw new Error((error == null ? void 0 : error.message) || "Network error");
|
|
52
|
+
}
|
|
53
|
+
const data = response.data;
|
|
54
|
+
if (data == null ? void 0 : data.errors) {
|
|
55
|
+
const firstError = Object.values(data.errors)[0];
|
|
56
|
+
if (Array.isArray(firstError)) {
|
|
57
|
+
throw new Error(firstError[0]);
|
|
58
|
+
}
|
|
59
|
+
throw new Error("Validation error");
|
|
60
|
+
}
|
|
61
|
+
if (data == null ? void 0 : data.message) {
|
|
62
|
+
throw new Error(data.message);
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
65
|
+
}
|
|
48
66
|
var api = {
|
|
49
67
|
async post(operation, url, payload) {
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
try {
|
|
69
|
+
const res = await import_http_client.authClient.post(url, payload ?? {});
|
|
70
|
+
return res.data;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
normalizeError(error);
|
|
73
|
+
}
|
|
52
74
|
},
|
|
53
75
|
async get(operation, url, query) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
76
|
+
try {
|
|
77
|
+
const res = await import_http_client.authClient.get(url, {
|
|
78
|
+
params: query
|
|
79
|
+
});
|
|
80
|
+
return res.data;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
normalizeError(error);
|
|
83
|
+
}
|
|
58
84
|
}
|
|
59
85
|
};
|
|
60
86
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
// src/api-client.ts
|
|
2
2
|
import { authClient } from "@justins-home/http-client";
|
|
3
|
+
function normalizeError(error) {
|
|
4
|
+
const response = error == null ? void 0 : error.response;
|
|
5
|
+
if (!response) {
|
|
6
|
+
throw new Error((error == null ? void 0 : error.message) || "Network error");
|
|
7
|
+
}
|
|
8
|
+
const data = response.data;
|
|
9
|
+
if (data == null ? void 0 : data.errors) {
|
|
10
|
+
const firstError = Object.values(data.errors)[0];
|
|
11
|
+
if (Array.isArray(firstError)) {
|
|
12
|
+
throw new Error(firstError[0]);
|
|
13
|
+
}
|
|
14
|
+
throw new Error("Validation error");
|
|
15
|
+
}
|
|
16
|
+
if (data == null ? void 0 : data.message) {
|
|
17
|
+
throw new Error(data.message);
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
20
|
+
}
|
|
3
21
|
var api = {
|
|
4
22
|
async post(operation, url, payload) {
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
try {
|
|
24
|
+
const res = await authClient.post(url, payload ?? {});
|
|
25
|
+
return res.data;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
normalizeError(error);
|
|
28
|
+
}
|
|
7
29
|
},
|
|
8
30
|
async get(operation, url, query) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
try {
|
|
32
|
+
const res = await authClient.get(url, {
|
|
33
|
+
params: query
|
|
34
|
+
});
|
|
35
|
+
return res.data;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
normalizeError(error);
|
|
38
|
+
}
|
|
13
39
|
}
|
|
14
40
|
};
|
|
15
41
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justins-home/api-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@justins-home/
|
|
8
|
-
"@justins-home/
|
|
7
|
+
"@justins-home/types": "1.0.0",
|
|
8
|
+
"@justins-home/http-client": "1.0.0"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
package/src/api-client.ts
CHANGED
|
@@ -19,14 +19,49 @@ type ApiResponse<T extends OperationId> = operations[T] extends {
|
|
|
19
19
|
? R
|
|
20
20
|
: unknown;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes Laravel API errors
|
|
24
|
+
*/
|
|
25
|
+
function normalizeError(error: any): never {
|
|
26
|
+
const response = error?.response;
|
|
27
|
+
|
|
28
|
+
if (!response) {
|
|
29
|
+
throw new Error(error?.message || 'Network error');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const data = response.data;
|
|
33
|
+
|
|
34
|
+
// Laravel validation errors
|
|
35
|
+
if (data?.errors) {
|
|
36
|
+
const firstError = Object.values(data.errors)[0];
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(firstError)) {
|
|
39
|
+
throw new Error(firstError[0]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new Error('Validation error');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Standard Laravel API error
|
|
46
|
+
if (data?.message) {
|
|
47
|
+
throw new Error(data.message);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
22
53
|
export const api = {
|
|
23
54
|
async post<T extends OperationId>(
|
|
24
55
|
operation: T,
|
|
25
56
|
url: string,
|
|
26
57
|
payload?: ApiRequest<T>,
|
|
27
58
|
): Promise<ApiResponse<T>> {
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
try {
|
|
60
|
+
const res = await authClient.post(url, payload ?? {});
|
|
61
|
+
return res.data;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
normalizeError(error);
|
|
64
|
+
}
|
|
30
65
|
},
|
|
31
66
|
|
|
32
67
|
async get<T extends OperationId>(
|
|
@@ -34,10 +69,14 @@ export const api = {
|
|
|
34
69
|
url: string,
|
|
35
70
|
query?: ApiRequest<T>,
|
|
36
71
|
): Promise<ApiResponse<T>> {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
72
|
+
try {
|
|
73
|
+
const res = await authClient.get(url, {
|
|
74
|
+
params: query,
|
|
75
|
+
});
|
|
40
76
|
|
|
41
|
-
|
|
77
|
+
return res.data;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
normalizeError(error);
|
|
80
|
+
}
|
|
42
81
|
},
|
|
43
82
|
};
|
package/src/authService.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { publicClient, request } from '@justins-home/http-client';
|
|
2
|
-
|
|
3
|
-
export const authService = {
|
|
4
|
-
async login(data: { email: string; password: string }) {
|
|
5
|
-
return request(publicClient, publicClient.post('/auth/login', data));
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
async logout() {
|
|
9
|
-
return request(publicClient, publicClient.post('/auth/logout'));
|
|
10
|
-
},
|
|
11
|
-
};
|
package/src/inspectionService.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { authClient, request } from '@justins-home/http-client';
|
|
2
|
-
import { InspectionResource } from '@justins-home/types';
|
|
3
|
-
|
|
4
|
-
export const inspectionService = {
|
|
5
|
-
async getInspections(): Promise<InspectionResource[]> {
|
|
6
|
-
return request(authClient, authClient.get('/inspections'));
|
|
7
|
-
},
|
|
8
|
-
};
|
package/src/listingService.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { authClient, request } from '@justins-home/http-client';
|
|
2
|
-
import { ListingResource } from '@justins-home/types';
|
|
3
|
-
|
|
4
|
-
export const listingService = {
|
|
5
|
-
async getListings(): Promise<ListingResource[]> {
|
|
6
|
-
return request(authClient, authClient.get('/listings'));
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
async getListing(uid: string): Promise<ListingResource> {
|
|
10
|
-
return request(authClient, authClient.get(`/listings/${uid}`));
|
|
11
|
-
},
|
|
12
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { authClient, request } from '@justins-home/http-client';
|
|
2
|
-
import { MaintenanceRequestResource } from '@justins-home/types';
|
|
3
|
-
|
|
4
|
-
export const maintenanceService = {
|
|
5
|
-
async getRequests(): Promise<MaintenanceRequestResource[]> {
|
|
6
|
-
return request(authClient, authClient.get('/maintenance'));
|
|
7
|
-
},
|
|
8
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { authClient, request } from '@justins-home/http-client';
|
|
2
|
-
import { NotificationResource } from '@justins-home/types';
|
|
3
|
-
|
|
4
|
-
export const notificationService = {
|
|
5
|
-
async getNotifications(): Promise<NotificationResource[]> {
|
|
6
|
-
return request(authClient, authClient.get('/notifications'));
|
|
7
|
-
},
|
|
8
|
-
};
|
package/src/tenancyService.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { authClient, request } from '@justins-home/http-client';
|
|
2
|
-
import { TenancyResource } from '@justins-home/types';
|
|
3
|
-
|
|
4
|
-
export const tenancyService = {
|
|
5
|
-
async getTenancies(): Promise<TenancyResource[]> {
|
|
6
|
-
return request(authClient, authClient.get('/tenancies'));
|
|
7
|
-
},
|
|
8
|
-
};
|