@mapcreator/api 0.0.0-co-edit.0

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.
Files changed (274) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +86 -0
  3. package/cjs/api/apiCommon.d.ts +7 -0
  4. package/cjs/api/apiCommon.d.ts.map +1 -0
  5. package/cjs/api/apiCommon.js +31 -0
  6. package/cjs/api/apiCommon.js.map +1 -0
  7. package/cjs/api/choropleth.d.ts +138 -0
  8. package/cjs/api/choropleth.d.ts.map +1 -0
  9. package/cjs/api/choropleth.js +41 -0
  10. package/cjs/api/choropleth.js.map +1 -0
  11. package/cjs/api/color.d.ts +16 -0
  12. package/cjs/api/color.d.ts.map +1 -0
  13. package/cjs/api/color.js +8 -0
  14. package/cjs/api/color.js.map +1 -0
  15. package/cjs/api/dimension.d.ts +25 -0
  16. package/cjs/api/dimension.d.ts.map +1 -0
  17. package/cjs/api/dimension.js +14 -0
  18. package/cjs/api/dimension.js.map +1 -0
  19. package/cjs/api/dimensionSet.d.ts +15 -0
  20. package/cjs/api/dimensionSet.d.ts.map +1 -0
  21. package/cjs/api/dimensionSet.js +7 -0
  22. package/cjs/api/dimensionSet.js.map +1 -0
  23. package/cjs/api/feature.d.ts +16 -0
  24. package/cjs/api/feature.d.ts.map +1 -0
  25. package/cjs/api/feature.js +8 -0
  26. package/cjs/api/feature.js.map +1 -0
  27. package/cjs/api/font.d.ts +32 -0
  28. package/cjs/api/font.d.ts.map +1 -0
  29. package/cjs/api/font.js +15 -0
  30. package/cjs/api/font.js.map +1 -0
  31. package/cjs/api/fontFamily.d.ts +17 -0
  32. package/cjs/api/fontFamily.d.ts.map +1 -0
  33. package/cjs/api/fontFamily.js +17 -0
  34. package/cjs/api/fontFamily.js.map +1 -0
  35. package/cjs/api/geocode.d.ts +10 -0
  36. package/cjs/api/geocode.d.ts.map +1 -0
  37. package/cjs/api/geocode.js +9 -0
  38. package/cjs/api/geocode.js.map +1 -0
  39. package/cjs/api/highlight.d.ts +41 -0
  40. package/cjs/api/highlight.d.ts.map +1 -0
  41. package/cjs/api/highlight.js +25 -0
  42. package/cjs/api/highlight.js.map +1 -0
  43. package/cjs/api/insetMap.d.ts +37 -0
  44. package/cjs/api/insetMap.d.ts.map +1 -0
  45. package/cjs/api/insetMap.js +47 -0
  46. package/cjs/api/insetMap.js.map +1 -0
  47. package/cjs/api/job.d.ts +45 -0
  48. package/cjs/api/job.d.ts.map +1 -0
  49. package/cjs/api/job.js +77 -0
  50. package/cjs/api/job.js.map +1 -0
  51. package/cjs/api/jobResult.d.ts +40 -0
  52. package/cjs/api/jobResult.d.ts.map +1 -0
  53. package/cjs/api/jobResult.js +35 -0
  54. package/cjs/api/jobResult.js.map +1 -0
  55. package/cjs/api/jobRevision.d.ts +76 -0
  56. package/cjs/api/jobRevision.d.ts.map +1 -0
  57. package/cjs/api/jobRevision.js +126 -0
  58. package/cjs/api/jobRevision.js.map +1 -0
  59. package/cjs/api/jobShare.d.ts +26 -0
  60. package/cjs/api/jobShare.d.ts.map +1 -0
  61. package/cjs/api/jobShare.js +9 -0
  62. package/cjs/api/jobShare.js.map +1 -0
  63. package/cjs/api/jobType.d.ts +17 -0
  64. package/cjs/api/jobType.d.ts.map +1 -0
  65. package/cjs/api/jobType.js +11 -0
  66. package/cjs/api/jobType.js.map +1 -0
  67. package/cjs/api/language.d.ts +17 -0
  68. package/cjs/api/language.d.ts.map +1 -0
  69. package/cjs/api/language.js +3 -0
  70. package/cjs/api/language.js.map +1 -0
  71. package/cjs/api/layer.d.ts +26 -0
  72. package/cjs/api/layer.d.ts.map +1 -0
  73. package/cjs/api/layer.js +14 -0
  74. package/cjs/api/layer.js.map +1 -0
  75. package/cjs/api/layerFaq.d.ts +27 -0
  76. package/cjs/api/layerFaq.d.ts.map +1 -0
  77. package/cjs/api/layerFaq.js +16 -0
  78. package/cjs/api/layerFaq.js.map +1 -0
  79. package/cjs/api/layerGroup.d.ts +16 -0
  80. package/cjs/api/layerGroup.d.ts.map +1 -0
  81. package/cjs/api/layerGroup.js +36 -0
  82. package/cjs/api/layerGroup.js.map +1 -0
  83. package/cjs/api/mapstyleSet.d.ts +32 -0
  84. package/cjs/api/mapstyleSet.d.ts.map +1 -0
  85. package/cjs/api/mapstyleSet.js +28 -0
  86. package/cjs/api/mapstyleSet.js.map +1 -0
  87. package/cjs/api/message.d.ts +32 -0
  88. package/cjs/api/message.d.ts.map +1 -0
  89. package/cjs/api/message.js +37 -0
  90. package/cjs/api/message.js.map +1 -0
  91. package/cjs/api/organisation.d.ts +41 -0
  92. package/cjs/api/organisation.d.ts.map +1 -0
  93. package/cjs/api/organisation.js +41 -0
  94. package/cjs/api/organisation.js.map +1 -0
  95. package/cjs/api/resources.d.ts +65 -0
  96. package/cjs/api/resources.d.ts.map +1 -0
  97. package/cjs/api/resources.js +61 -0
  98. package/cjs/api/resources.js.map +1 -0
  99. package/cjs/api/svg.d.ts +21 -0
  100. package/cjs/api/svg.d.ts.map +1 -0
  101. package/cjs/api/svg.js +15 -0
  102. package/cjs/api/svg.js.map +1 -0
  103. package/cjs/api/svgSet.d.ts +22 -0
  104. package/cjs/api/svgSet.d.ts.map +1 -0
  105. package/cjs/api/svgSet.js +25 -0
  106. package/cjs/api/svgSet.js.map +1 -0
  107. package/cjs/api/user.d.ts +129 -0
  108. package/cjs/api/user.d.ts.map +1 -0
  109. package/cjs/api/user.js +145 -0
  110. package/cjs/api/user.js.map +1 -0
  111. package/cjs/index.d.ts +28 -0
  112. package/cjs/index.d.ts.map +1 -0
  113. package/cjs/index.js +53 -0
  114. package/cjs/index.js.map +1 -0
  115. package/cjs/oauth.d.ts +31 -0
  116. package/cjs/oauth.d.ts.map +1 -0
  117. package/cjs/oauth.js +76 -0
  118. package/cjs/oauth.js.map +1 -0
  119. package/cjs/utils.d.ts +72 -0
  120. package/cjs/utils.d.ts.map +1 -0
  121. package/cjs/utils.js +220 -0
  122. package/cjs/utils.js.map +1 -0
  123. package/esm/api/apiCommon.d.ts +7 -0
  124. package/esm/api/apiCommon.d.ts.map +1 -0
  125. package/esm/api/apiCommon.js +28 -0
  126. package/esm/api/apiCommon.js.map +1 -0
  127. package/esm/api/choropleth.d.ts +138 -0
  128. package/esm/api/choropleth.d.ts.map +1 -0
  129. package/esm/api/choropleth.js +34 -0
  130. package/esm/api/choropleth.js.map +1 -0
  131. package/esm/api/color.d.ts +16 -0
  132. package/esm/api/color.d.ts.map +1 -0
  133. package/esm/api/color.js +5 -0
  134. package/esm/api/color.js.map +1 -0
  135. package/esm/api/dimension.d.ts +25 -0
  136. package/esm/api/dimension.d.ts.map +1 -0
  137. package/esm/api/dimension.js +11 -0
  138. package/esm/api/dimension.js.map +1 -0
  139. package/esm/api/dimensionSet.d.ts +15 -0
  140. package/esm/api/dimensionSet.d.ts.map +1 -0
  141. package/esm/api/dimensionSet.js +4 -0
  142. package/esm/api/dimensionSet.js.map +1 -0
  143. package/esm/api/feature.d.ts +16 -0
  144. package/esm/api/feature.d.ts.map +1 -0
  145. package/esm/api/feature.js +5 -0
  146. package/esm/api/feature.js.map +1 -0
  147. package/esm/api/font.d.ts +32 -0
  148. package/esm/api/font.d.ts.map +1 -0
  149. package/esm/api/font.js +11 -0
  150. package/esm/api/font.js.map +1 -0
  151. package/esm/api/fontFamily.d.ts +17 -0
  152. package/esm/api/fontFamily.d.ts.map +1 -0
  153. package/esm/api/fontFamily.js +13 -0
  154. package/esm/api/fontFamily.js.map +1 -0
  155. package/esm/api/geocode.d.ts +10 -0
  156. package/esm/api/geocode.d.ts.map +1 -0
  157. package/esm/api/geocode.js +6 -0
  158. package/esm/api/geocode.js.map +1 -0
  159. package/esm/api/highlight.d.ts +41 -0
  160. package/esm/api/highlight.d.ts.map +1 -0
  161. package/esm/api/highlight.js +21 -0
  162. package/esm/api/highlight.js.map +1 -0
  163. package/esm/api/insetMap.d.ts +37 -0
  164. package/esm/api/insetMap.d.ts.map +1 -0
  165. package/esm/api/insetMap.js +42 -0
  166. package/esm/api/insetMap.js.map +1 -0
  167. package/esm/api/job.d.ts +45 -0
  168. package/esm/api/job.d.ts.map +1 -0
  169. package/esm/api/job.js +64 -0
  170. package/esm/api/job.js.map +1 -0
  171. package/esm/api/jobResult.d.ts +40 -0
  172. package/esm/api/jobResult.d.ts.map +1 -0
  173. package/esm/api/jobResult.js +30 -0
  174. package/esm/api/jobResult.js.map +1 -0
  175. package/esm/api/jobRevision.d.ts +76 -0
  176. package/esm/api/jobRevision.d.ts.map +1 -0
  177. package/esm/api/jobRevision.js +114 -0
  178. package/esm/api/jobRevision.js.map +1 -0
  179. package/esm/api/jobShare.d.ts +26 -0
  180. package/esm/api/jobShare.d.ts.map +1 -0
  181. package/esm/api/jobShare.js +6 -0
  182. package/esm/api/jobShare.js.map +1 -0
  183. package/esm/api/jobType.d.ts +17 -0
  184. package/esm/api/jobType.d.ts.map +1 -0
  185. package/esm/api/jobType.js +8 -0
  186. package/esm/api/jobType.js.map +1 -0
  187. package/esm/api/language.d.ts +17 -0
  188. package/esm/api/language.d.ts.map +1 -0
  189. package/esm/api/language.js +2 -0
  190. package/esm/api/language.js.map +1 -0
  191. package/esm/api/layer.d.ts +26 -0
  192. package/esm/api/layer.d.ts.map +1 -0
  193. package/esm/api/layer.js +11 -0
  194. package/esm/api/layer.js.map +1 -0
  195. package/esm/api/layerFaq.d.ts +27 -0
  196. package/esm/api/layerFaq.d.ts.map +1 -0
  197. package/esm/api/layerFaq.js +12 -0
  198. package/esm/api/layerFaq.js.map +1 -0
  199. package/esm/api/layerGroup.d.ts +16 -0
  200. package/esm/api/layerGroup.d.ts.map +1 -0
  201. package/esm/api/layerGroup.js +33 -0
  202. package/esm/api/layerGroup.js.map +1 -0
  203. package/esm/api/mapstyleSet.d.ts +32 -0
  204. package/esm/api/mapstyleSet.d.ts.map +1 -0
  205. package/esm/api/mapstyleSet.js +24 -0
  206. package/esm/api/mapstyleSet.js.map +1 -0
  207. package/esm/api/message.d.ts +32 -0
  208. package/esm/api/message.d.ts.map +1 -0
  209. package/esm/api/message.js +32 -0
  210. package/esm/api/message.js.map +1 -0
  211. package/esm/api/organisation.d.ts +41 -0
  212. package/esm/api/organisation.d.ts.map +1 -0
  213. package/esm/api/organisation.js +35 -0
  214. package/esm/api/organisation.js.map +1 -0
  215. package/esm/api/resources.d.ts +65 -0
  216. package/esm/api/resources.d.ts.map +1 -0
  217. package/esm/api/resources.js +55 -0
  218. package/esm/api/resources.js.map +1 -0
  219. package/esm/api/svg.d.ts +21 -0
  220. package/esm/api/svg.d.ts.map +1 -0
  221. package/esm/api/svg.js +11 -0
  222. package/esm/api/svg.js.map +1 -0
  223. package/esm/api/svgSet.d.ts +22 -0
  224. package/esm/api/svgSet.d.ts.map +1 -0
  225. package/esm/api/svgSet.js +21 -0
  226. package/esm/api/svgSet.js.map +1 -0
  227. package/esm/api/user.d.ts +129 -0
  228. package/esm/api/user.d.ts.map +1 -0
  229. package/esm/api/user.js +126 -0
  230. package/esm/api/user.js.map +1 -0
  231. package/esm/index.d.ts +28 -0
  232. package/esm/index.d.ts.map +1 -0
  233. package/esm/index.js +28 -0
  234. package/esm/index.js.map +1 -0
  235. package/esm/oauth.d.ts +31 -0
  236. package/esm/oauth.d.ts.map +1 -0
  237. package/esm/oauth.js +68 -0
  238. package/esm/oauth.js.map +1 -0
  239. package/esm/utils.d.ts +72 -0
  240. package/esm/utils.d.ts.map +1 -0
  241. package/esm/utils.js +206 -0
  242. package/esm/utils.js.map +1 -0
  243. package/package.json +80 -0
  244. package/src/README.md +126 -0
  245. package/src/api/apiCommon.ts +70 -0
  246. package/src/api/choropleth.ts +228 -0
  247. package/src/api/color.ts +22 -0
  248. package/src/api/dimension.ts +44 -0
  249. package/src/api/dimensionSet.ts +20 -0
  250. package/src/api/feature.ts +22 -0
  251. package/src/api/font.ts +57 -0
  252. package/src/api/fontFamily.ts +43 -0
  253. package/src/api/geocode.ts +17 -0
  254. package/src/api/highlight.ts +87 -0
  255. package/src/api/insetMap.ts +95 -0
  256. package/src/api/job.ts +139 -0
  257. package/src/api/jobResult.ts +95 -0
  258. package/src/api/jobRevision.ts +281 -0
  259. package/src/api/jobShare.ts +35 -0
  260. package/src/api/jobType.ts +26 -0
  261. package/src/api/language.ts +19 -0
  262. package/src/api/layer.ts +38 -0
  263. package/src/api/layerFaq.ts +53 -0
  264. package/src/api/layerGroup.ts +69 -0
  265. package/src/api/mapstyleSet.ts +70 -0
  266. package/src/api/message.ts +80 -0
  267. package/src/api/organisation.ts +96 -0
  268. package/src/api/resources.ts +153 -0
  269. package/src/api/svg.ts +33 -0
  270. package/src/api/svgSet.ts +56 -0
  271. package/src/api/user.ts +327 -0
  272. package/src/index.ts +44 -0
  273. package/src/oauth.ts +90 -0
  274. package/src/utils.ts +342 -0
@@ -0,0 +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
+ }
@@ -0,0 +1,95 @@
1
+ import { apiHost, authenticate, getAuthorizationHeaders, 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 = getAuthorizationHeaders('GET');
67
+ const response = await fetch(href, { headers, ...!token && { credentials: 'include' } })
68
+ .catch((error: Error) => { throw new NetworkError(error?.message ?? error) });
69
+
70
+ if (response.ok) {
71
+ return response.json().catch(() => {
72
+ throw new APIError({
73
+ success: false,
74
+ error: { type: 'SyntaxError', message: 'Malformed JSON response' },
75
+ });
76
+ }) as Promise<TopoJSON>;
77
+ } else {
78
+ // eslint-disable-next-line default-case
79
+ switch (response.status) {
80
+ case 401:
81
+ await authenticate();
82
+ break; // NO-OP
83
+ case 403:
84
+ case 404:
85
+ case 406:
86
+ case 429:
87
+ throw new APIError({
88
+ success: false,
89
+ error: { type: 'HttpException', message: response.statusText },
90
+ });
91
+ }
92
+
93
+ throw new HTTPError(response);
94
+ }
95
+ }
package/src/api/job.ts ADDED
@@ -0,0 +1,139 @@
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
+ private: boolean;
27
+ };
28
+
29
+ export type ApiJob = {
30
+ data: {
31
+ id: number; // The job id (sortable)
32
+ job_type_id: number; // The id of the job type (searchable)
33
+ user_id: number; // The user id (searchable)
34
+ title: string; // The title of the job (searchable, sortable)
35
+ description: string | null; // The description of the job (searchable, sortable)
36
+ share_token: string | null; // The token used for sharing this job
37
+ autosave_preview_path: string | null; // The preview path of the Job
38
+ job_folder_id: number | null; // TODO: not present in API specification!
39
+ job_folder_name?: string | null; // TODO: not present in API specification!
40
+ star: boolean; // TODO: not present in API specification!
41
+ private: boolean;
42
+ } & ApiCommonData;
43
+ } & Omit<ApiSuccess, 'data'> | ApiError;
44
+
45
+ export type ApiJobData = Flatten<Exclude<ApiJob, ApiError>['data']>;
46
+
47
+ export const jobRevivers: Revivers<ApiJob, Job> = {
48
+ description: undefined,
49
+ share_token: undefined,
50
+ autosave_preview_path: undefined,
51
+
52
+ jobTypeId: () => 9,
53
+ jobFolderName: (data: ApiJobData) => data.job_folder_name ?? null,
54
+ createdAt: (data: ApiJobData) => data.created_at as string,
55
+ previewPath: (data: ApiJobData) => data.autosave_preview_path ?? undefined,
56
+ };
57
+
58
+ export async function createJob(title: string): Promise<Job> {
59
+ const path = `/v1/jobs`;
60
+ const body = { title, job_type_id: 9 };
61
+ const options = { revivers: jobRevivers };
62
+
63
+ // Technically, the returning `data` will contain only the following fields:
64
+ // Pick<ApiJobData, 'id' | 'job_type_id' | 'user_id' | 'title' | 'created_at' | 'updated_at'>
65
+
66
+ return request<ApiJob, Job>(path, body, null, options);
67
+ }
68
+
69
+ export async function getJob(jobId: number): Promise<Job> {
70
+ const path = `/v1/jobs/${jobId}`;
71
+ const options = { revivers: jobRevivers };
72
+
73
+ return request<ApiJob, Job>(path, null, null, options);
74
+ }
75
+
76
+ export async function deleteJob(jobId: number): Promise<Record<string, never>> {
77
+ const path = `/v1/jobs/${jobId}`;
78
+
79
+ return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
80
+ }
81
+
82
+ export async function updateJob(jobId: number, newTitle: string): Promise<Record<string, never>> {
83
+ const path = `/v1/jobs/${jobId}`;
84
+ const body = { title: newTitle };
85
+
86
+ return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
87
+ }
88
+
89
+ export async function updateJobFolder(jobId: number, folderId: number | null): Promise<Record<string, never>> {
90
+ const path = `/v1/jobs/${jobId}`;
91
+ const body = { job_folder_id: folderId };
92
+
93
+ return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
94
+ }
95
+
96
+ export async function starJob(jobId: number, star: boolean): Promise<Record<string, never>> {
97
+ const path = `/v1/jobs/${jobId}`;
98
+ const body = { star };
99
+
100
+ return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
101
+ }
102
+
103
+ export async function privateJob(jobId: number, privateValue: boolean): Promise<Record<string, never>> {
104
+ const path = `/v1/jobs/${jobId}`;
105
+ const body = { private: privateValue };
106
+
107
+ return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
108
+ }
109
+
110
+ export async function generateJobShare(
111
+ jobId: number,
112
+ visibility: JobShareVisibility,
113
+ ): Promise<JobShare> {
114
+ const path = `/v1/jobs/${jobId}/share`;
115
+ const body = { visibility };
116
+
117
+ return request<ApiJobShare, JobShare>(path, body);
118
+ }
119
+
120
+ export async function uploadJobPreview(
121
+ jobId: number,
122
+ preview: Blob,
123
+ ): Promise<Record<string, never>> {
124
+ const pathname = `/v1/jobs/${jobId}/preview`;
125
+ const path = `${pathname}?${deletedNoneParam}`;
126
+ const body = new FormData();
127
+
128
+ body.append('preview', preview);
129
+
130
+ return request<ApiCommon, Record<string, never>>(path, body);
131
+ }
132
+
133
+ export async function listFeaturedJobs(
134
+ title: string,
135
+ page: number,
136
+ options?: Record<string, unknown>,
137
+ ): Promise<JobSearchResult> {
138
+ return listJobs(`/v1/jobs/featured`, title, page, options);
139
+ }
@@ -0,0 +1,95 @@
1
+ import {
2
+ type ApiCommon,
3
+ type ApiCommonData,
4
+ type ApiError,
5
+ type ApiSuccess,
6
+ type Flatten,
7
+ type Revivers,
8
+ deletedNoneParam,
9
+ lastJobRevision,
10
+ request,
11
+ } from '../utils.js';
12
+
13
+ export type JobResult = {
14
+ jobRevisionId: number;
15
+ revision: number;
16
+ status: string;
17
+ };
18
+
19
+ export type ApiJobResult = {
20
+ data: {
21
+ job_revision_id: number; // The id of the job revision
22
+ revision: number; // The revision number of the job revision
23
+ mapstyle_id: number; // The id of the map style
24
+ interface_version: string; // The version of the interface (searchable, sortable)
25
+ fix: string; //
26
+ status: string; // The status of the job result (searchable, sortable)
27
+ fail_reason: string; // A human-readable reason of why the map failed to process
28
+ process_start: string; // The datetime when the job process started (searchable, sortable)
29
+ process_end: string; // The datetime when the job process ended (searchable, sortable)
30
+ dealt_with: boolean; // Checks if the Support fixed an issue (searchable, sortable)
31
+ bought: boolean; // Checks if the result is bought or not (searchable, sortable)
32
+ subscription_id: number; // The id of the subscription that was active when the map was created
33
+ callback: string; // URL to another API which can finish a map (searchable, sortable)
34
+ last_downloaded: string; // The last time the archive was downloaded (searchable, sortable)
35
+ } & ApiCommonData;
36
+ } & Omit<ApiSuccess, 'data'> | ApiError;
37
+
38
+ export type ApiJobResultData = Flatten<Exclude<ApiJobResult, ApiError>['data']>;
39
+
40
+ export const jobResultRevivers: Revivers<ApiJobResult, JobResult> = {
41
+ mapstyle_id: undefined,
42
+ interface_version: undefined,
43
+ fix: undefined,
44
+ fail_reason: undefined,
45
+ process_start: undefined,
46
+ process_end: undefined,
47
+ dealt_with: undefined,
48
+ bought: undefined,
49
+ subscription_id: undefined,
50
+ callback: undefined,
51
+ last_downloaded: undefined,
52
+ };
53
+
54
+ export async function uploadJobResultPreview(
55
+ jobId: number,
56
+ blob: Blob,
57
+ ): Promise<Record<string, never>> {
58
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/preview`;
59
+ const path = `${pathname}?${deletedNoneParam}`;
60
+ const body = new FormData();
61
+
62
+ body.append('preview', blob);
63
+
64
+ return request<ApiCommon, Record<string, never>>(path, body);
65
+ }
66
+
67
+ export type JobResultHostedImage = {
68
+ url: string;
69
+ message: string;
70
+ };
71
+
72
+ export type ApiJobResultHostedImage = {
73
+ data: {
74
+ url: string;
75
+ message: string;
76
+ } & ApiCommonData;
77
+ } & Omit<ApiSuccess, 'data'> | ApiError;
78
+
79
+ export type ApiJobResultHostedImageData = Flatten<Exclude<ApiJobResultHostedImage, ApiError>['data']>;
80
+
81
+ export async function uploadJobResultHostedImage(
82
+ jobId: number,
83
+ blob: Blob,
84
+ fileName: string,
85
+ fileType: 'jpg' | 'png' | 'svg',
86
+ ): Promise<JobResultHostedImage> {
87
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/hosted-${fileType}`;
88
+ const path = `${pathname}?${deletedNoneParam}`;
89
+ const body = new FormData();
90
+
91
+ body.append(fileType, blob);
92
+ body.append('filename', fileName);
93
+
94
+ return request<ApiJobResultHostedImage, JobResultHostedImage>(path, body);
95
+ }
@@ -0,0 +1,281 @@
1
+ import { apiHost, authenticate, getAuthorizationHeaders, token } from '../oauth.js';
2
+ import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
3
+ import type { ApiMapstyleSetData } from './mapstyleSet.js';
4
+ import type { ApiLanguageData } from './language.js';
5
+ import {
6
+ APIError,
7
+ type ApiCommon,
8
+ type ApiCommonData,
9
+ type ApiError,
10
+ type ApiSuccess,
11
+ type Flatten,
12
+ HTTPError,
13
+ NetworkError,
14
+ type Revivers,
15
+ defaultListHeader,
16
+ deletedNoneParam,
17
+ lastJobRevision,
18
+ request,
19
+ } from '../utils.js';
20
+
21
+ export type FileFormat =
22
+ | 'jpg'
23
+ | 'png'
24
+ | 'svg'
25
+ | 'pdf'
26
+ | 'tiff'
27
+ | 'eps'
28
+ | 'eps_log'
29
+ | 'mp4'
30
+ | 'mov'
31
+ | 'mkv'
32
+ | 'mxf'
33
+ | 'webm'
34
+ | 'jpg_sequence'
35
+ | 'png_sequence'
36
+ | 'web'
37
+ | 'web_download';
38
+
39
+ export type JobRevision = {
40
+ id: number;
41
+ jobId: number;
42
+ revision: number;
43
+ languageCode: string;
44
+ mapstyleSetId: number;
45
+ output: FileFormat;
46
+ };
47
+
48
+ export type ApiJobRevision = {
49
+ data: {
50
+ id: number; // The id of the job revision (sortable)
51
+ job_id: number; // The id of the job related to this revision (searchable, sortable)
52
+ revision: number; // The revision number (searchable, sortable)
53
+ language_code: string; // The language code of the revision (searchable, sortable)
54
+ mapstyle_set_id: number; // The id of the mapstyle set
55
+ archived: boolean; // Whether the revision has been generated (searchable, sortable)
56
+ output: FileFormat; // The output file type
57
+ } & ApiCommonData;
58
+ } & Omit<ApiSuccess, 'data'> | ApiError;
59
+
60
+ export type ApiJobRevisionData = Flatten<Exclude<ApiJobRevision, ApiError>['data']>;
61
+
62
+ export const jobRevisionRevivers: Revivers<ApiJobRevision, JobRevision> = {
63
+ archived: undefined,
64
+ };
65
+
66
+ export async function createJobRevision(
67
+ jobId: number,
68
+ languageCode: string,
69
+ mapstyleSetId: number,
70
+ layers: number[],
71
+ output: FileFormat,
72
+ jobObject: Record<string, unknown>,
73
+ skipValidation?: boolean
74
+ ): Promise<JobRevision> {
75
+ const pathname = `/v1/jobs/${jobId}/revisions`;
76
+ const path = `${pathname}?${deletedNoneParam}`;
77
+ const body = {
78
+ language_code: languageCode,
79
+ mapstyle_set_id: mapstyleSetId,
80
+ object: JSON.stringify(jobObject),
81
+ output,
82
+ layers,
83
+ ...skipValidation && { skip_validation: skipValidation },
84
+ };
85
+ const options = { revivers: jobRevisionRevivers };
86
+
87
+ return request<ApiJobRevision, JobRevision>(path, body, null, options);
88
+ }
89
+
90
+ export async function getJobRevision(jobId: number): Promise<JobRevision | undefined> {
91
+ const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}`;
92
+ const options = { revivers: jobRevisionRevivers };
93
+
94
+ return request<ApiJobRevision, JobRevision>(path, null, null, options).catch(() => undefined);
95
+ }
96
+
97
+ export async function getJobRevisionObject<JobObject>(jobId: number): Promise<JobObject> {
98
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/object`;
99
+ const path = `${pathname}?${deletedNoneParam}`;
100
+
101
+ return request<ApiCommon, string>(path).then(JSON.parse) as Promise<JobObject>;
102
+ }
103
+
104
+ export type JobCanBuild = {
105
+ canBuild: boolean;
106
+ paymentSource: string;
107
+ reason: string | null;
108
+ };
109
+
110
+ export type ApiJobCanBuild = {
111
+ data: {
112
+ can_build: boolean;
113
+ payment_source: string;
114
+ reason: string | null;
115
+ } & ApiCommonData;
116
+ } & Omit<ApiSuccess, 'data'> | ApiError;
117
+
118
+ // Also known as `canBuild()`
119
+ export async function getJobRevisionBuild(jobId: number): Promise<JobCanBuild> {
120
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build`;
121
+ const path = `${pathname}?${deletedNoneParam}`;
122
+
123
+ return request<ApiJobCanBuild, JobCanBuild>(path);
124
+ }
125
+
126
+ export type JobRevisionBuild = {
127
+ jobRevisionId: number;
128
+ revision: number;
129
+ status: string;
130
+ };
131
+
132
+ export type ApiJobRevisionBuild = {
133
+ data: {
134
+ job_revision_id: number; // The id of the job revision
135
+ status: string; // The status of the job result (searchable, sortable)
136
+ subscription_id: number; // The id of the subscription that was active when the map was created
137
+ process_start: string; // The datetime when the job process started (searchable, sortable)
138
+ process_end: string; // The datetime when the job process ended (searchable, sortable)
139
+ last_downloaded: string; // The last time the archive was downloaded (searchable, sortable)
140
+ bought: boolean; // Checks if the result is bought or not (searchable, sortable)
141
+ revision: number; // The revision number of the job revision
142
+ job_revision: ApiJobRevisionData;
143
+ } & ApiCommonData;
144
+ } & Omit<ApiSuccess, 'data'> | ApiError;
145
+
146
+ export type ApiJobRevisionBuildData = Flatten<Exclude<ApiJobRevisionBuild, ApiError>['data']>;
147
+
148
+ export const jobRevisionBuildRevivers: Revivers<ApiJobRevisionBuild, JobRevisionBuild> = {
149
+ subscription_id: undefined,
150
+ process_start: undefined,
151
+ process_end: undefined,
152
+ last_downloaded: undefined,
153
+ bought: undefined,
154
+ job_revision: undefined,
155
+ };
156
+
157
+ export async function registerJobRevisionBuild(
158
+ jobId: number,
159
+ status: string,
160
+ start: Date,
161
+ end: Date,
162
+ ): Promise<JobRevisionBuild> {
163
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build/register`;
164
+ const path = `${pathname}?${deletedNoneParam}`;
165
+ const body = { status, process_start: start, process_end: end };
166
+ const options = { revivers: jobRevisionBuildRevivers };
167
+
168
+ return request<ApiJobRevisionBuild, JobRevisionBuild>(path, body, null, options);
169
+ }
170
+
171
+ export async function cloneJobRevision(jobId: number, newTitle?: string): Promise<JobRevision> {
172
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/clone`;
173
+ const path = `${pathname}?${deletedNoneParam}`;
174
+ const body = { title: newTitle ?? null };
175
+ const options = {
176
+ revivers: {
177
+ ...jobRevisionRevivers,
178
+ layers: undefined,
179
+ language: undefined,
180
+ mapstyle_set: undefined,
181
+ },
182
+ };
183
+
184
+ type ApiJobRevisionWithData = {
185
+ data: ApiJobRevisionData & {
186
+ layers: ApiLayerData[];
187
+ language: ApiLanguageData;
188
+ mapstyle_set: ApiMapstyleSetData;
189
+ };
190
+ } & Omit<ApiSuccess, 'data'> | ApiError;
191
+
192
+ return request<ApiJobRevisionWithData, JobRevision>(path, body, null, options);
193
+ }
194
+
195
+ export async function listJobRevisionLayers(jobId: number): Promise<Layer[]> {
196
+ const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/layers`;
197
+ const options = { revivers: layerRevivers };
198
+
199
+ type ApiLayerArray = {
200
+ data: ApiLayerData[];
201
+ } & Omit<ApiSuccess, 'data'> | ApiError;
202
+
203
+ return request<ApiLayerArray, Layer>(path, null, defaultListHeader, options);
204
+ }
205
+
206
+ export type JobRevisionOutputUrl = { url: string };
207
+
208
+ export type ApiJobRevisionOutputUrl = {
209
+ data: JobRevisionOutputUrl & ApiCommonData;
210
+ } & Omit<ApiSuccess, 'data'> | ApiError;
211
+
212
+ export async function getJobRevisionOutputUrl(jobId: number): Promise<JobRevisionOutputUrl> {
213
+ await createJobRevisionBuild(jobId);
214
+
215
+ const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/output-url`;
216
+
217
+ return request<ApiJobRevisionOutputUrl, JobRevisionOutputUrl>(path);
218
+ }
219
+
220
+ export type JobRevisionOutput = { blob: Blob; filename?: string | undefined };
221
+
222
+ export async function getJobRevisionOutput(jobId: number): Promise<JobRevisionOutput> {
223
+ await createJobRevisionBuild(jobId);
224
+
225
+ const href = `${apiHost}/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/output`;
226
+ const headers = getAuthorizationHeaders('GET');
227
+ const response = await fetch(href, { headers, ...!token && { credentials: 'include' } })
228
+ .catch((error: Error) => { throw new NetworkError(error?.message ?? error) });
229
+
230
+ if (response.ok) {
231
+ const blob = await response.blob().catch(() => {
232
+ throw new APIError({ success: false, error: { type: 'TypeError', message: 'Malformed Blob response' } });
233
+ });
234
+ const contentDisposition = response.headers.get('Content-Disposition');
235
+
236
+ if (contentDisposition) {
237
+ const filenameRegex = /filename\*\s*=\s*UTF-8''(.+)/i;
238
+ const filenameMatch = contentDisposition.match(filenameRegex);
239
+
240
+ if (filenameMatch?.[1]) {
241
+ return { blob, filename: filenameMatch[1] };
242
+ }
243
+
244
+ const fallbackRegex = /filename\s*=\s*"([^"]+)"/i;
245
+ const fallbackMatch = contentDisposition.match(fallbackRegex);
246
+
247
+ if (fallbackMatch?.[1]) {
248
+ return { blob, filename: fallbackMatch[1] };
249
+ }
250
+ }
251
+
252
+ return { blob };
253
+ } else {
254
+ // eslint-disable-next-line default-case
255
+ switch (response.status) {
256
+ case 401:
257
+ await authenticate();
258
+ break; // NO-OP
259
+ case 403:
260
+ case 404:
261
+ case 406:
262
+ case 429:
263
+ throw new APIError(
264
+ (await response.json().catch(() => ({
265
+ success: false,
266
+ error: { type: 'HttpException', message: response.statusText },
267
+ }))) as ApiError,
268
+ );
269
+ }
270
+
271
+ throw new HTTPError(response);
272
+ }
273
+ }
274
+
275
+ async function createJobRevisionBuild(jobId: number, skipValidation?: boolean): Promise<string> {
276
+ const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build`;
277
+ const path = `${pathname}?${deletedNoneParam}`;
278
+ const body = skipValidation ? { skip_validation: skipValidation } : null;
279
+
280
+ return request<ApiCommon, string>(path, body, null, { method: 'POST' });
281
+ }