@mapcreator/api 0.0.0-saga.1 → 0.0.0-saga.3
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/cjs/api/choropleth.d.ts +3 -3
- package/cjs/api/choropleth.d.ts.map +1 -1
- package/cjs/api/choropleth.js +17 -4
- package/cjs/api/choropleth.js.map +1 -1
- package/cjs/api/insetMap.d.ts +37 -0
- package/cjs/api/insetMap.d.ts.map +1 -0
- package/cjs/api/insetMap.js +49 -0
- package/cjs/api/insetMap.js.map +1 -0
- package/cjs/api/job.d.ts +1 -0
- package/cjs/api/job.d.ts.map +1 -1
- package/cjs/api/job.js.map +1 -1
- package/cjs/api/jobResult.d.ts +1 -1
- package/cjs/api/jobResult.d.ts.map +1 -1
- package/cjs/api/jobResult.js +1 -1
- package/cjs/api/jobResult.js.map +1 -1
- package/cjs/api/jobRevision.d.ts +2 -2
- package/cjs/api/jobRevision.d.ts.map +1 -1
- package/cjs/api/jobRevision.js +1 -1
- package/cjs/api/jobRevision.js.map +1 -1
- package/cjs/api/organisation.d.ts +2 -1
- package/cjs/api/organisation.d.ts.map +1 -1
- package/cjs/api/organisation.js +1 -2
- package/cjs/api/organisation.js.map +1 -1
- package/cjs/api/resources.d.ts +1 -1
- package/cjs/api/resources.d.ts.map +1 -1
- package/cjs/api/resources.js.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/esm/api/choropleth.d.ts +3 -3
- package/esm/api/choropleth.d.ts.map +1 -1
- package/esm/api/choropleth.js +17 -4
- package/esm/api/choropleth.js.map +1 -1
- package/esm/api/insetMap.d.ts +37 -0
- package/esm/api/insetMap.d.ts.map +1 -0
- package/esm/api/insetMap.js +44 -0
- package/esm/api/insetMap.js.map +1 -0
- package/esm/api/job.d.ts +1 -0
- package/esm/api/job.d.ts.map +1 -1
- package/esm/api/job.js.map +1 -1
- package/esm/api/jobResult.d.ts +1 -1
- package/esm/api/jobResult.d.ts.map +1 -1
- package/esm/api/jobResult.js +1 -1
- package/esm/api/jobResult.js.map +1 -1
- package/esm/api/jobRevision.d.ts +2 -2
- package/esm/api/jobRevision.d.ts.map +1 -1
- package/esm/api/jobRevision.js +1 -1
- package/esm/api/jobRevision.js.map +1 -1
- package/esm/api/organisation.d.ts +2 -1
- package/esm/api/organisation.d.ts.map +1 -1
- package/esm/api/organisation.js +1 -2
- package/esm/api/organisation.js.map +1 -1
- package/esm/api/resources.d.ts +1 -1
- package/esm/api/resources.d.ts.map +1 -1
- package/esm/api/resources.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/api/apiCommon.ts +70 -70
- package/src/api/choropleth.ts +125 -105
- package/src/api/color.ts +22 -22
- package/src/api/dimension.ts +44 -44
- package/src/api/dimensionSet.ts +20 -20
- package/src/api/feature.ts +22 -22
- package/src/api/font.ts +49 -49
- package/src/api/fontFamily.ts +43 -43
- package/src/api/highlight.ts +87 -87
- package/src/api/insetMap.ts +96 -0
- package/src/api/job.ts +130 -129
- package/src/api/jobResult.ts +95 -95
- package/src/api/jobRevision.ts +279 -278
- package/src/api/jobShare.ts +35 -35
- package/src/api/jobType.ts +26 -26
- package/src/api/language.ts +19 -19
- package/src/api/layer.ts +38 -38
- package/src/api/layerFaq.ts +53 -53
- package/src/api/layerGroup.ts +69 -69
- package/src/api/mapstyleSet.ts +48 -48
- package/src/api/message.ts +80 -80
- package/src/api/organisation.ts +95 -95
- package/src/api/resources.ts +145 -143
- package/src/api/svg.ts +33 -33
- package/src/api/svgSet.ts +56 -56
- package/src/api/user.ts +327 -327
- package/src/index.ts +43 -42
- package/src/oauth.ts +314 -314
- package/src/utils.ts +342 -342
package/src/api/highlight.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import type { FeatureCollection } from 'geojson';
|
|
2
|
-
import type { SnakeCase } from 'type-fest';
|
|
3
|
-
import {
|
|
4
|
-
APIMeta,
|
|
5
|
-
type ApiCommonData,
|
|
6
|
-
type ApiError,
|
|
7
|
-
type ApiSuccess,
|
|
8
|
-
type Flatten,
|
|
9
|
-
defaultListHeader,
|
|
10
|
-
getSearchParams,
|
|
11
|
-
request,
|
|
12
|
-
} from '../utils.js';
|
|
13
|
-
|
|
14
|
-
type FieldName = 'id' | 'name' | 'description' | 'previewPath' | 'previewJson';
|
|
15
|
-
|
|
16
|
-
export type PartialVectorHighlight = Pick<VectorHighlight, FieldName>;
|
|
17
|
-
|
|
18
|
-
export type VectorHighlight = {
|
|
19
|
-
id: number;
|
|
20
|
-
name: string;
|
|
21
|
-
description: string;
|
|
22
|
-
previewPath: string | null;
|
|
23
|
-
previewJson: FeatureCollection | null;
|
|
24
|
-
|
|
25
|
-
vectorSetUrl: string;
|
|
26
|
-
sourceLayerName: string;
|
|
27
|
-
|
|
28
|
-
lngMin: number;
|
|
29
|
-
lngMax: number;
|
|
30
|
-
latMin: number;
|
|
31
|
-
latMax: number;
|
|
32
|
-
|
|
33
|
-
keys: string[];
|
|
34
|
-
properties: Record<string, unknown>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type ApiVectorHighlight = {
|
|
38
|
-
data: {
|
|
39
|
-
id: number;
|
|
40
|
-
name: string;
|
|
41
|
-
description: string;
|
|
42
|
-
preview_path: string | null;
|
|
43
|
-
preview_json: FeatureCollection | null;
|
|
44
|
-
|
|
45
|
-
vector_set_url: string;
|
|
46
|
-
source_layer_name: string;
|
|
47
|
-
|
|
48
|
-
lng_min: number;
|
|
49
|
-
lng_max: number;
|
|
50
|
-
lat_min: number;
|
|
51
|
-
lat_max: number;
|
|
52
|
-
|
|
53
|
-
keys: string[];
|
|
54
|
-
properties: Record<string, unknown>;
|
|
55
|
-
} & ApiCommonData;
|
|
56
|
-
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
57
|
-
|
|
58
|
-
export type ApiVectorHighlightData = Flatten<Exclude<ApiVectorHighlight, ApiError>['data']>;
|
|
59
|
-
|
|
60
|
-
export async function listVectorHighlights(name: string): Promise<PartialVectorHighlight[]> {
|
|
61
|
-
const pathname = `/v1/highlights/vector`;
|
|
62
|
-
const query = getSearchParams({ search: { name } });
|
|
63
|
-
const path = `${pathname}?${query}`;
|
|
64
|
-
|
|
65
|
-
// Only request first 50 results
|
|
66
|
-
const headers = { ...defaultListHeader };
|
|
67
|
-
const options = { withMeta: true };
|
|
68
|
-
|
|
69
|
-
type ApiVectorHighlightArray = {
|
|
70
|
-
data: Array<Pick<ApiVectorHighlightData, SnakeCase<FieldName>>>;
|
|
71
|
-
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
72
|
-
|
|
73
|
-
return request<ApiVectorHighlightArray, PartialVectorHighlight>(path, null, headers, options)
|
|
74
|
-
.catch((error: Error) => {
|
|
75
|
-
if (error instanceof APIMeta) {
|
|
76
|
-
return (error as APIMeta<ApiVectorHighlightArray, PartialVectorHighlight>).data;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
throw error;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export async function getVectorHighlight(highlightId: number): Promise<VectorHighlight> {
|
|
84
|
-
const path = `/v1/highlights/vector/${highlightId}`;
|
|
85
|
-
|
|
86
|
-
return request<ApiVectorHighlight, VectorHighlight>(path);
|
|
87
|
-
}
|
|
1
|
+
import type { FeatureCollection } from 'geojson';
|
|
2
|
+
import type { SnakeCase } from 'type-fest';
|
|
3
|
+
import {
|
|
4
|
+
APIMeta,
|
|
5
|
+
type ApiCommonData,
|
|
6
|
+
type ApiError,
|
|
7
|
+
type ApiSuccess,
|
|
8
|
+
type Flatten,
|
|
9
|
+
defaultListHeader,
|
|
10
|
+
getSearchParams,
|
|
11
|
+
request,
|
|
12
|
+
} from '../utils.js';
|
|
13
|
+
|
|
14
|
+
type FieldName = 'id' | 'name' | 'description' | 'previewPath' | 'previewJson';
|
|
15
|
+
|
|
16
|
+
export type PartialVectorHighlight = Pick<VectorHighlight, FieldName>;
|
|
17
|
+
|
|
18
|
+
export type VectorHighlight = {
|
|
19
|
+
id: number;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
previewPath: string | null;
|
|
23
|
+
previewJson: FeatureCollection | null;
|
|
24
|
+
|
|
25
|
+
vectorSetUrl: string;
|
|
26
|
+
sourceLayerName: string;
|
|
27
|
+
|
|
28
|
+
lngMin: number;
|
|
29
|
+
lngMax: number;
|
|
30
|
+
latMin: number;
|
|
31
|
+
latMax: number;
|
|
32
|
+
|
|
33
|
+
keys: string[];
|
|
34
|
+
properties: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ApiVectorHighlight = {
|
|
38
|
+
data: {
|
|
39
|
+
id: number;
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
preview_path: string | null;
|
|
43
|
+
preview_json: FeatureCollection | null;
|
|
44
|
+
|
|
45
|
+
vector_set_url: string;
|
|
46
|
+
source_layer_name: string;
|
|
47
|
+
|
|
48
|
+
lng_min: number;
|
|
49
|
+
lng_max: number;
|
|
50
|
+
lat_min: number;
|
|
51
|
+
lat_max: number;
|
|
52
|
+
|
|
53
|
+
keys: string[];
|
|
54
|
+
properties: Record<string, unknown>;
|
|
55
|
+
} & ApiCommonData;
|
|
56
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
57
|
+
|
|
58
|
+
export type ApiVectorHighlightData = Flatten<Exclude<ApiVectorHighlight, ApiError>['data']>;
|
|
59
|
+
|
|
60
|
+
export async function listVectorHighlights(name: string): Promise<PartialVectorHighlight[]> {
|
|
61
|
+
const pathname = `/v1/highlights/vector`;
|
|
62
|
+
const query = getSearchParams({ search: { name } });
|
|
63
|
+
const path = `${pathname}?${query}`;
|
|
64
|
+
|
|
65
|
+
// Only request first 50 results
|
|
66
|
+
const headers = { ...defaultListHeader };
|
|
67
|
+
const options = { withMeta: true };
|
|
68
|
+
|
|
69
|
+
type ApiVectorHighlightArray = {
|
|
70
|
+
data: Array<Pick<ApiVectorHighlightData, SnakeCase<FieldName>>>;
|
|
71
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
72
|
+
|
|
73
|
+
return request<ApiVectorHighlightArray, PartialVectorHighlight>(path, null, headers, options)
|
|
74
|
+
.catch((error: Error) => {
|
|
75
|
+
if (error instanceof APIMeta) {
|
|
76
|
+
return (error as APIMeta<ApiVectorHighlightArray, PartialVectorHighlight>).data;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
throw error;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function getVectorHighlight(highlightId: number): Promise<VectorHighlight> {
|
|
84
|
+
const path = `/v1/highlights/vector/${highlightId}`;
|
|
85
|
+
|
|
86
|
+
return request<ApiVectorHighlight, VectorHighlight>(path);
|
|
87
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { apiHost, authenticate, token } from '../oauth.js';
|
|
2
|
+
import {
|
|
3
|
+
APIError,
|
|
4
|
+
type ApiCommonData,
|
|
5
|
+
type ApiError,
|
|
6
|
+
type ApiSuccess,
|
|
7
|
+
type Flatten,
|
|
8
|
+
HTTPError,
|
|
9
|
+
NetworkError,
|
|
10
|
+
request,
|
|
11
|
+
} from '../utils.js';
|
|
12
|
+
|
|
13
|
+
export type InsetMap = {
|
|
14
|
+
id: number;
|
|
15
|
+
description: string;
|
|
16
|
+
jsonFilename: string;
|
|
17
|
+
latMin: number;
|
|
18
|
+
lngMin: number;
|
|
19
|
+
latMax: number;
|
|
20
|
+
lngMax: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ApiInsetMap = {
|
|
24
|
+
data: {
|
|
25
|
+
id: number;
|
|
26
|
+
description: string;
|
|
27
|
+
json_filename: string;
|
|
28
|
+
lat_min: number;
|
|
29
|
+
lng_min: number;
|
|
30
|
+
lat_max: number;
|
|
31
|
+
lng_max: number;
|
|
32
|
+
} & ApiCommonData;
|
|
33
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
34
|
+
|
|
35
|
+
export type ApiInsetMapData = Flatten<Exclude<ApiInsetMap, ApiError>['data']>;
|
|
36
|
+
|
|
37
|
+
type Boundary = {
|
|
38
|
+
topLeft: {
|
|
39
|
+
lat: number;
|
|
40
|
+
lng: number;
|
|
41
|
+
};
|
|
42
|
+
bottomRight: {
|
|
43
|
+
lat: number;
|
|
44
|
+
lng: number;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export async function listInsetMaps(boundary: Boundary): Promise<InsetMap[]> {
|
|
49
|
+
const path = `/v1/inset-maps/for-boundary`;
|
|
50
|
+
|
|
51
|
+
type ApiInsetMapArray = {
|
|
52
|
+
data: ApiInsetMapData[];
|
|
53
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
54
|
+
|
|
55
|
+
return request<ApiInsetMapArray, InsetMap>(path, { boundary });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function getInsetMap(insetMapId: number): Promise<InsetMap> {
|
|
59
|
+
const path = `/v1/inset-maps/${insetMapId}`;
|
|
60
|
+
|
|
61
|
+
return request<ApiInsetMap, InsetMap>(path);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function getInsetMapTopoJson<TopoJSON>(insetMapId: number): Promise<TopoJSON> {
|
|
65
|
+
const href = `${apiHost}/v1/inset-maps/${insetMapId}/json`;
|
|
66
|
+
const headers = { Accept: 'application/json', ...(token ? { Authorization: token.toString() } : null) };
|
|
67
|
+
const response = await fetch(href, { headers }).catch((error: Error) => {
|
|
68
|
+
throw new NetworkError(error?.message ?? error);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (response.ok) {
|
|
72
|
+
return response.json().catch(() => {
|
|
73
|
+
throw new APIError({
|
|
74
|
+
success: false,
|
|
75
|
+
error: { type: 'SyntaxError', message: 'Malformed JSON response' },
|
|
76
|
+
});
|
|
77
|
+
}) as Promise<TopoJSON>;
|
|
78
|
+
} else {
|
|
79
|
+
// eslint-disable-next-line default-case
|
|
80
|
+
switch (response.status) {
|
|
81
|
+
case 401:
|
|
82
|
+
await authenticate();
|
|
83
|
+
break; // NO-OP
|
|
84
|
+
case 403:
|
|
85
|
+
case 404:
|
|
86
|
+
case 406:
|
|
87
|
+
case 429:
|
|
88
|
+
throw new APIError({
|
|
89
|
+
success: false,
|
|
90
|
+
error: { type: 'HttpException', message: response.statusText },
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
throw new HTTPError(response);
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/api/job.ts
CHANGED
|
@@ -1,129 +1,130 @@
|
|
|
1
|
-
import type { ApiJobShare, JobShare, JobShareVisibility } from './jobShare.js';
|
|
2
|
-
import { type JobSearchResult, listJobs } from './apiCommon.js';
|
|
3
|
-
import {
|
|
4
|
-
type ApiCommon,
|
|
5
|
-
type ApiCommonData,
|
|
6
|
-
type ApiError,
|
|
7
|
-
type ApiSuccess,
|
|
8
|
-
type Flatten,
|
|
9
|
-
type Revivers,
|
|
10
|
-
deletedNoneParam,
|
|
11
|
-
request,
|
|
12
|
-
} from '../utils.js';
|
|
13
|
-
|
|
14
|
-
export type Job = {
|
|
15
|
-
id: number;
|
|
16
|
-
jobTypeId: number;
|
|
17
|
-
title: string;
|
|
18
|
-
previewPath: string | undefined;
|
|
19
|
-
createdAt: string;
|
|
20
|
-
star: boolean;
|
|
21
|
-
jobFolderId: number | null;
|
|
22
|
-
userEmail: string | undefined;
|
|
23
|
-
jobFolderName: string | null;
|
|
24
|
-
userId: number;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} &
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
1
|
+
import type { ApiJobShare, JobShare, JobShareVisibility } from './jobShare.js';
|
|
2
|
+
import { type JobSearchResult, listJobs } from './apiCommon.js';
|
|
3
|
+
import {
|
|
4
|
+
type ApiCommon,
|
|
5
|
+
type ApiCommonData,
|
|
6
|
+
type ApiError,
|
|
7
|
+
type ApiSuccess,
|
|
8
|
+
type Flatten,
|
|
9
|
+
type Revivers,
|
|
10
|
+
deletedNoneParam,
|
|
11
|
+
request,
|
|
12
|
+
} from '../utils.js';
|
|
13
|
+
|
|
14
|
+
export type Job = {
|
|
15
|
+
id: number;
|
|
16
|
+
jobTypeId: number;
|
|
17
|
+
title: string;
|
|
18
|
+
previewPath: string | undefined;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
star: boolean;
|
|
21
|
+
jobFolderId: number | null;
|
|
22
|
+
userEmail: string | undefined;
|
|
23
|
+
jobFolderName: string | null;
|
|
24
|
+
userId: number;
|
|
25
|
+
orgName: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ApiJob = {
|
|
29
|
+
data: {
|
|
30
|
+
id: number; // The job id (sortable)
|
|
31
|
+
job_type_id: number; // The id of the job type (searchable)
|
|
32
|
+
user_id: number; // The user id (searchable)
|
|
33
|
+
title: string; // The title of the job (searchable, sortable)
|
|
34
|
+
description: string | null; // The description of the job (searchable, sortable)
|
|
35
|
+
share_token: string | null; // The token used for sharing this job
|
|
36
|
+
autosave_preview_path: string | null; // The preview path of the Job
|
|
37
|
+
job_folder_id: number | null; // TODO: not present in API specification!
|
|
38
|
+
job_folder_name?: string | null; // TODO: not present in API specification!
|
|
39
|
+
star: boolean; // TODO: not present in API specification!
|
|
40
|
+
} & ApiCommonData;
|
|
41
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
42
|
+
|
|
43
|
+
export type ApiJobData = Flatten<Exclude<ApiJob, ApiError>['data']>;
|
|
44
|
+
|
|
45
|
+
export const jobRevivers: Revivers<ApiJob, Job> = {
|
|
46
|
+
description: undefined,
|
|
47
|
+
share_token: undefined,
|
|
48
|
+
autosave_preview_path: undefined,
|
|
49
|
+
|
|
50
|
+
jobTypeId: () => 9,
|
|
51
|
+
jobFolderName: (data: ApiJobData) => data.job_folder_name ?? null,
|
|
52
|
+
createdAt: (data: ApiJobData) => data.created_at as string,
|
|
53
|
+
previewPath: (data: ApiJobData) => data.autosave_preview_path ?? undefined,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export async function createJob(title: string): Promise<Job> {
|
|
57
|
+
const path = `/v1/jobs`;
|
|
58
|
+
const body = { title, job_type_id: 9 };
|
|
59
|
+
const options = { revivers: jobRevivers };
|
|
60
|
+
|
|
61
|
+
// Technically, the returning `data` will contain only the following fields:
|
|
62
|
+
// Pick<ApiJobData, 'id' | 'job_type_id' | 'user_id' | 'title' | 'created_at' | 'updated_at'>
|
|
63
|
+
|
|
64
|
+
return request<ApiJob, Job>(path, body, null, options);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function getJob(jobId: number): Promise<Job> {
|
|
68
|
+
const path = `/v1/jobs/${jobId}`;
|
|
69
|
+
const options = { revivers: jobRevivers };
|
|
70
|
+
|
|
71
|
+
return request<ApiJob, Job>(path, null, null, options);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function deleteJob(jobId: number): Promise<Record<string, never>> {
|
|
75
|
+
const path = `/v1/jobs/${jobId}`;
|
|
76
|
+
|
|
77
|
+
return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function updateJob(jobId: number, newTitle: string): Promise<Record<string, never>> {
|
|
81
|
+
const path = `/v1/jobs/${jobId}`;
|
|
82
|
+
const body = { title: newTitle };
|
|
83
|
+
|
|
84
|
+
return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function updateJobFolder(jobId: number, folderId: number | null): Promise<Record<string, never>> {
|
|
88
|
+
const path = `/v1/jobs/${jobId}`;
|
|
89
|
+
const body = { job_folder_id: folderId };
|
|
90
|
+
|
|
91
|
+
return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function starJob(jobId: number, star: boolean): Promise<Record<string, never>> {
|
|
95
|
+
const path = `/v1/jobs/${jobId}`;
|
|
96
|
+
const body = { star };
|
|
97
|
+
|
|
98
|
+
return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function generateJobShare(
|
|
102
|
+
jobId: number,
|
|
103
|
+
visibility: JobShareVisibility,
|
|
104
|
+
): Promise<JobShare> {
|
|
105
|
+
const path = `/v1/jobs/${jobId}/share`;
|
|
106
|
+
const body = { visibility };
|
|
107
|
+
|
|
108
|
+
return request<ApiJobShare, JobShare>(path, body);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function uploadJobPreview(
|
|
112
|
+
jobId: number,
|
|
113
|
+
preview: Blob,
|
|
114
|
+
): Promise<Record<string, never>> {
|
|
115
|
+
const pathname = `/v1/jobs/${jobId}/preview`;
|
|
116
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
117
|
+
const body = new FormData();
|
|
118
|
+
|
|
119
|
+
body.append('preview', preview);
|
|
120
|
+
|
|
121
|
+
return request<ApiCommon, Record<string, never>>(path, body);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function listFeaturedJobs(
|
|
125
|
+
title: string,
|
|
126
|
+
page: number,
|
|
127
|
+
options?: Record<string, unknown>,
|
|
128
|
+
): Promise<JobSearchResult> {
|
|
129
|
+
return listJobs(`/v1/jobs/featured`, title, page, options);
|
|
130
|
+
}
|