@mapcreator/api 0.0.0-fonts.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 (265) 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 +61 -0
  8. package/cjs/api/choropleth.d.ts.map +1 -0
  9. package/cjs/api/choropleth.js +32 -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 +31 -0
  28. package/cjs/api/font.d.ts.map +1 -0
  29. package/cjs/api/font.js +16 -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/highlight.d.ts +41 -0
  36. package/cjs/api/highlight.d.ts.map +1 -0
  37. package/cjs/api/highlight.js +25 -0
  38. package/cjs/api/highlight.js.map +1 -0
  39. package/cjs/api/insetMap.d.ts +37 -0
  40. package/cjs/api/insetMap.d.ts.map +1 -0
  41. package/cjs/api/insetMap.js +49 -0
  42. package/cjs/api/insetMap.js.map +1 -0
  43. package/cjs/api/job.d.ts +42 -0
  44. package/cjs/api/job.d.ts.map +1 -0
  45. package/cjs/api/job.js +71 -0
  46. package/cjs/api/job.js.map +1 -0
  47. package/cjs/api/jobResult.d.ts +40 -0
  48. package/cjs/api/jobResult.d.ts.map +1 -0
  49. package/cjs/api/jobResult.js +35 -0
  50. package/cjs/api/jobResult.js.map +1 -0
  51. package/cjs/api/jobRevision.d.ts +76 -0
  52. package/cjs/api/jobRevision.d.ts.map +1 -0
  53. package/cjs/api/jobRevision.js +132 -0
  54. package/cjs/api/jobRevision.js.map +1 -0
  55. package/cjs/api/jobShare.d.ts +26 -0
  56. package/cjs/api/jobShare.d.ts.map +1 -0
  57. package/cjs/api/jobShare.js +9 -0
  58. package/cjs/api/jobShare.js.map +1 -0
  59. package/cjs/api/jobType.d.ts +17 -0
  60. package/cjs/api/jobType.d.ts.map +1 -0
  61. package/cjs/api/jobType.js +11 -0
  62. package/cjs/api/jobType.js.map +1 -0
  63. package/cjs/api/language.d.ts +17 -0
  64. package/cjs/api/language.d.ts.map +1 -0
  65. package/cjs/api/language.js +3 -0
  66. package/cjs/api/language.js.map +1 -0
  67. package/cjs/api/layer.d.ts +26 -0
  68. package/cjs/api/layer.d.ts.map +1 -0
  69. package/cjs/api/layer.js +14 -0
  70. package/cjs/api/layer.js.map +1 -0
  71. package/cjs/api/layerFaq.d.ts +27 -0
  72. package/cjs/api/layerFaq.d.ts.map +1 -0
  73. package/cjs/api/layerFaq.js +16 -0
  74. package/cjs/api/layerFaq.js.map +1 -0
  75. package/cjs/api/layerGroup.d.ts +16 -0
  76. package/cjs/api/layerGroup.d.ts.map +1 -0
  77. package/cjs/api/layerGroup.js +36 -0
  78. package/cjs/api/layerGroup.js.map +1 -0
  79. package/cjs/api/mapstyleSet.d.ts +31 -0
  80. package/cjs/api/mapstyleSet.d.ts.map +1 -0
  81. package/cjs/api/mapstyleSet.js +19 -0
  82. package/cjs/api/mapstyleSet.js.map +1 -0
  83. package/cjs/api/message.d.ts +32 -0
  84. package/cjs/api/message.d.ts.map +1 -0
  85. package/cjs/api/message.js +37 -0
  86. package/cjs/api/message.js.map +1 -0
  87. package/cjs/api/organisation.d.ts +41 -0
  88. package/cjs/api/organisation.d.ts.map +1 -0
  89. package/cjs/api/organisation.js +41 -0
  90. package/cjs/api/organisation.js.map +1 -0
  91. package/cjs/api/resources.d.ts +65 -0
  92. package/cjs/api/resources.d.ts.map +1 -0
  93. package/cjs/api/resources.js +61 -0
  94. package/cjs/api/resources.js.map +1 -0
  95. package/cjs/api/svg.d.ts +21 -0
  96. package/cjs/api/svg.d.ts.map +1 -0
  97. package/cjs/api/svg.js +15 -0
  98. package/cjs/api/svg.js.map +1 -0
  99. package/cjs/api/svgSet.d.ts +22 -0
  100. package/cjs/api/svgSet.d.ts.map +1 -0
  101. package/cjs/api/svgSet.js +25 -0
  102. package/cjs/api/svgSet.js.map +1 -0
  103. package/cjs/api/user.d.ts +128 -0
  104. package/cjs/api/user.d.ts.map +1 -0
  105. package/cjs/api/user.js +146 -0
  106. package/cjs/api/user.js.map +1 -0
  107. package/cjs/index.d.ts +27 -0
  108. package/cjs/index.d.ts.map +1 -0
  109. package/cjs/index.js +52 -0
  110. package/cjs/index.js.map +1 -0
  111. package/cjs/oauth.d.ts +27 -0
  112. package/cjs/oauth.d.ts.map +1 -0
  113. package/cjs/oauth.js +245 -0
  114. package/cjs/oauth.js.map +1 -0
  115. package/cjs/utils.d.ts +72 -0
  116. package/cjs/utils.d.ts.map +1 -0
  117. package/cjs/utils.js +220 -0
  118. package/cjs/utils.js.map +1 -0
  119. package/esm/api/apiCommon.d.ts +7 -0
  120. package/esm/api/apiCommon.d.ts.map +1 -0
  121. package/esm/api/apiCommon.js +28 -0
  122. package/esm/api/apiCommon.js.map +1 -0
  123. package/esm/api/choropleth.d.ts +61 -0
  124. package/esm/api/choropleth.d.ts.map +1 -0
  125. package/esm/api/choropleth.js +27 -0
  126. package/esm/api/choropleth.js.map +1 -0
  127. package/esm/api/color.d.ts +16 -0
  128. package/esm/api/color.d.ts.map +1 -0
  129. package/esm/api/color.js +5 -0
  130. package/esm/api/color.js.map +1 -0
  131. package/esm/api/dimension.d.ts +25 -0
  132. package/esm/api/dimension.d.ts.map +1 -0
  133. package/esm/api/dimension.js +11 -0
  134. package/esm/api/dimension.js.map +1 -0
  135. package/esm/api/dimensionSet.d.ts +15 -0
  136. package/esm/api/dimensionSet.d.ts.map +1 -0
  137. package/esm/api/dimensionSet.js +4 -0
  138. package/esm/api/dimensionSet.js.map +1 -0
  139. package/esm/api/feature.d.ts +16 -0
  140. package/esm/api/feature.d.ts.map +1 -0
  141. package/esm/api/feature.js +5 -0
  142. package/esm/api/feature.js.map +1 -0
  143. package/esm/api/font.d.ts +31 -0
  144. package/esm/api/font.d.ts.map +1 -0
  145. package/esm/api/font.js +12 -0
  146. package/esm/api/font.js.map +1 -0
  147. package/esm/api/fontFamily.d.ts +17 -0
  148. package/esm/api/fontFamily.d.ts.map +1 -0
  149. package/esm/api/fontFamily.js +13 -0
  150. package/esm/api/fontFamily.js.map +1 -0
  151. package/esm/api/highlight.d.ts +41 -0
  152. package/esm/api/highlight.d.ts.map +1 -0
  153. package/esm/api/highlight.js +21 -0
  154. package/esm/api/highlight.js.map +1 -0
  155. package/esm/api/insetMap.d.ts +37 -0
  156. package/esm/api/insetMap.d.ts.map +1 -0
  157. package/esm/api/insetMap.js +44 -0
  158. package/esm/api/insetMap.js.map +1 -0
  159. package/esm/api/job.d.ts +42 -0
  160. package/esm/api/job.d.ts.map +1 -0
  161. package/esm/api/job.js +59 -0
  162. package/esm/api/job.js.map +1 -0
  163. package/esm/api/jobResult.d.ts +40 -0
  164. package/esm/api/jobResult.d.ts.map +1 -0
  165. package/esm/api/jobResult.js +30 -0
  166. package/esm/api/jobResult.js.map +1 -0
  167. package/esm/api/jobRevision.d.ts +76 -0
  168. package/esm/api/jobRevision.d.ts.map +1 -0
  169. package/esm/api/jobRevision.js +120 -0
  170. package/esm/api/jobRevision.js.map +1 -0
  171. package/esm/api/jobShare.d.ts +26 -0
  172. package/esm/api/jobShare.d.ts.map +1 -0
  173. package/esm/api/jobShare.js +6 -0
  174. package/esm/api/jobShare.js.map +1 -0
  175. package/esm/api/jobType.d.ts +17 -0
  176. package/esm/api/jobType.d.ts.map +1 -0
  177. package/esm/api/jobType.js +8 -0
  178. package/esm/api/jobType.js.map +1 -0
  179. package/esm/api/language.d.ts +17 -0
  180. package/esm/api/language.d.ts.map +1 -0
  181. package/esm/api/language.js +2 -0
  182. package/esm/api/language.js.map +1 -0
  183. package/esm/api/layer.d.ts +26 -0
  184. package/esm/api/layer.d.ts.map +1 -0
  185. package/esm/api/layer.js +11 -0
  186. package/esm/api/layer.js.map +1 -0
  187. package/esm/api/layerFaq.d.ts +27 -0
  188. package/esm/api/layerFaq.d.ts.map +1 -0
  189. package/esm/api/layerFaq.js +12 -0
  190. package/esm/api/layerFaq.js.map +1 -0
  191. package/esm/api/layerGroup.d.ts +16 -0
  192. package/esm/api/layerGroup.d.ts.map +1 -0
  193. package/esm/api/layerGroup.js +33 -0
  194. package/esm/api/layerGroup.js.map +1 -0
  195. package/esm/api/mapstyleSet.d.ts +31 -0
  196. package/esm/api/mapstyleSet.d.ts.map +1 -0
  197. package/esm/api/mapstyleSet.js +16 -0
  198. package/esm/api/mapstyleSet.js.map +1 -0
  199. package/esm/api/message.d.ts +32 -0
  200. package/esm/api/message.d.ts.map +1 -0
  201. package/esm/api/message.js +32 -0
  202. package/esm/api/message.js.map +1 -0
  203. package/esm/api/organisation.d.ts +41 -0
  204. package/esm/api/organisation.d.ts.map +1 -0
  205. package/esm/api/organisation.js +35 -0
  206. package/esm/api/organisation.js.map +1 -0
  207. package/esm/api/resources.d.ts +65 -0
  208. package/esm/api/resources.d.ts.map +1 -0
  209. package/esm/api/resources.js +55 -0
  210. package/esm/api/resources.js.map +1 -0
  211. package/esm/api/svg.d.ts +21 -0
  212. package/esm/api/svg.d.ts.map +1 -0
  213. package/esm/api/svg.js +11 -0
  214. package/esm/api/svg.js.map +1 -0
  215. package/esm/api/svgSet.d.ts +22 -0
  216. package/esm/api/svgSet.d.ts.map +1 -0
  217. package/esm/api/svgSet.js +21 -0
  218. package/esm/api/svgSet.js.map +1 -0
  219. package/esm/api/user.d.ts +128 -0
  220. package/esm/api/user.d.ts.map +1 -0
  221. package/esm/api/user.js +127 -0
  222. package/esm/api/user.js.map +1 -0
  223. package/esm/index.d.ts +27 -0
  224. package/esm/index.d.ts.map +1 -0
  225. package/esm/index.js +27 -0
  226. package/esm/index.js.map +1 -0
  227. package/esm/oauth.d.ts +27 -0
  228. package/esm/oauth.d.ts.map +1 -0
  229. package/esm/oauth.js +237 -0
  230. package/esm/oauth.js.map +1 -0
  231. package/esm/utils.d.ts +72 -0
  232. package/esm/utils.d.ts.map +1 -0
  233. package/esm/utils.js +206 -0
  234. package/esm/utils.js.map +1 -0
  235. package/package.json +80 -0
  236. package/src/README.md +126 -0
  237. package/src/api/apiCommon.ts +70 -0
  238. package/src/api/choropleth.ts +132 -0
  239. package/src/api/color.ts +22 -0
  240. package/src/api/dimension.ts +44 -0
  241. package/src/api/dimensionSet.ts +20 -0
  242. package/src/api/feature.ts +22 -0
  243. package/src/api/font.ts +49 -0
  244. package/src/api/fontFamily.ts +43 -0
  245. package/src/api/highlight.ts +87 -0
  246. package/src/api/insetMap.ts +96 -0
  247. package/src/api/job.ts +130 -0
  248. package/src/api/jobResult.ts +95 -0
  249. package/src/api/jobRevision.ts +279 -0
  250. package/src/api/jobShare.ts +35 -0
  251. package/src/api/jobType.ts +26 -0
  252. package/src/api/language.ts +19 -0
  253. package/src/api/layer.ts +38 -0
  254. package/src/api/layerFaq.ts +53 -0
  255. package/src/api/layerGroup.ts +69 -0
  256. package/src/api/mapstyleSet.ts +48 -0
  257. package/src/api/message.ts +80 -0
  258. package/src/api/organisation.ts +95 -0
  259. package/src/api/resources.ts +153 -0
  260. package/src/api/svg.ts +33 -0
  261. package/src/api/svgSet.ts +56 -0
  262. package/src/api/user.ts +327 -0
  263. package/src/index.ts +43 -0
  264. package/src/oauth.ts +314 -0
  265. package/src/utils.ts +342 -0
@@ -0,0 +1,44 @@
1
+ import type { ApiCommonData, ApiError, ApiSuccess, Flatten, Revivers } from '../utils.js';
2
+
3
+ export type OutputUnit =
4
+ | 'millimeter'
5
+ | 'centimeter'
6
+ | 'inch'
7
+ | 'pixel'
8
+ | 'pica';
9
+
10
+ export type Dimension = {
11
+ id: number;
12
+ dimensionSetId: number;
13
+ name: string;
14
+ width: number;
15
+ height: number;
16
+ dpi: number;
17
+ unit: OutputUnit;
18
+ };
19
+
20
+ export type ApiDimension = {
21
+ data: {
22
+ id: number; // The dimension id (sortable)
23
+ dimension_set_id: number; // The id of the dimension set
24
+ name: string; // The name of dimension (searchable, sortable)
25
+ width: number; // The width of the dimension (searchable, sortable)
26
+ height: number; // The height of the dimension (searchable, sortable)
27
+ dpi: number; // The dpi of the dimension
28
+ unit: string; // The unit of this dimension
29
+ } & ApiCommonData;
30
+ } & Omit<ApiSuccess, 'data'> | ApiError;
31
+
32
+ export type ApiDimensionData = Flatten<Exclude<ApiDimension, ApiError>['data']>;
33
+
34
+ const keyToUnit: { [key: string]: OutputUnit } = {
35
+ MM: 'millimeter',
36
+ CM: 'centimeter',
37
+ IN: 'inch',
38
+ PX: 'pixel',
39
+ PICA: 'pica',
40
+ };
41
+
42
+ export const dimensionRevivers: Revivers<ApiDimension, Dimension> = {
43
+ unit: (data: ApiDimensionData) => keyToUnit[data.unit],
44
+ };
@@ -0,0 +1,20 @@
1
+ import type { ApiCommonData, ApiError, ApiSuccess, Flatten, Revivers } from '../utils.js';
2
+
3
+ export type DimensionSet = {
4
+ id: number;
5
+ name: string;
6
+ };
7
+
8
+ export type ApiDimensionSet = {
9
+ data: {
10
+ id: number; // The dimension set id (sortable)
11
+ name: string; // The dimension set name (searchable, sortable)
12
+ order?: number; // TODO: not present in API specification!
13
+ } & ApiCommonData;
14
+ } & Omit<ApiSuccess, 'data'> | ApiError;
15
+
16
+ export type ApiDimensionSetData = Flatten<Exclude<ApiDimensionSet, ApiError>['data']>;
17
+
18
+ export const dimensionSetRevivers: Revivers<ApiDimensionSet, DimensionSet> = {
19
+ order: undefined,
20
+ };
@@ -0,0 +1,22 @@
1
+ import type { ApiCommonData, ApiError, ApiSuccess, Flatten, Revivers } from '../utils.js';
2
+
3
+ export type Feature = {
4
+ id: number;
5
+ name: string;
6
+ };
7
+
8
+ export type ApiFeature = {
9
+ data: {
10
+ id: number; // The feature id
11
+ name: string; // The feature name (searchable, sortable)
12
+ description: string; // The description of the feature (searchable, sortable)
13
+ order?: number; // TODO: not present in API specification!
14
+ } & ApiCommonData;
15
+ } & Omit<ApiSuccess, 'data'> | ApiError;
16
+
17
+ export type ApiFeatureData = Flatten<Exclude<ApiFeature, ApiError>['data']>;
18
+
19
+ export const featureRevivers: Revivers<ApiFeature, Feature> = {
20
+ description: undefined,
21
+ order: undefined,
22
+ };
@@ -0,0 +1,49 @@
1
+ import { type ApiCommonData, type ApiError, type ApiSuccess, type Flatten, type Revivers, getSearchParams, request } from '../utils.js';
2
+
3
+ export type Font = {
4
+ id: number;
5
+ fontFamilyId: number;
6
+ name: string;
7
+ label: string;
8
+ weight: number;
9
+ style: string;
10
+ };
11
+
12
+ export type ApiFont = {
13
+ data: {
14
+ id: number; // The id of the font (sortable)
15
+ font_family_id: number; // The id of the font family
16
+ name: string; // The name of the font (searchable, sortable)
17
+ style: string; // The font style (searchable, sortable)
18
+ stretch: string; // The font stretch (searchable, sortable)
19
+ weight: number; // The font weight (searchable, sortable)
20
+ label: string; // The label of the font (searchable, sortable)
21
+ order?: number; // TODO: not present in API specification!
22
+ } & ApiCommonData;
23
+ } & Omit<ApiSuccess, 'data'> | ApiError;
24
+
25
+ export type ApiFontData = Flatten<Exclude<ApiFont, ApiError>['data']>;
26
+
27
+ type FontSearchOptions = {
28
+ family?: string;
29
+ style?: string;
30
+ weight?: string;
31
+ };
32
+
33
+ export const fontRevivers: Revivers<ApiFont, Font> = {
34
+ stretch: undefined,
35
+ order: undefined,
36
+ };
37
+
38
+ export async function getFonts(searchOptions: FontSearchOptions): Promise<Font[] | Font> {
39
+ const pathname = `/v1/fonts/search`;
40
+ const query = getSearchParams(searchOptions);
41
+
42
+ const path = `${pathname}?${query}`;
43
+
44
+ type ApiFontArray = {
45
+ data: ApiFontData[];
46
+ } & Omit<ApiSuccess, 'data'> | ApiError;
47
+
48
+ return request<ApiFontArray, Font>(path);
49
+ }
@@ -0,0 +1,43 @@
1
+ import { type ApiFontData, type Font, fontRevivers } from './font.js';
2
+ import {
3
+ type ApiCommonData,
4
+ type ApiError,
5
+ type ApiSuccess,
6
+ type Flatten,
7
+ type Revivers,
8
+ defaultListHeader,
9
+ getSearchParams,
10
+ request,
11
+ } from '../utils.js';
12
+
13
+ export type FontFamily = {
14
+ id: number;
15
+ name: string;
16
+ };
17
+
18
+ export type ApiFontFamily = {
19
+ data: {
20
+ id: number; // The id of the font family (sortable)
21
+ name: string; // The name of the font family (searchable, sortable)
22
+ order?: number; // TODO: not present in API specification!
23
+ } & ApiCommonData;
24
+ } & Omit<ApiSuccess, 'data'> | ApiError;
25
+
26
+ export type ApiFontFamilyData = Flatten<Exclude<ApiFontFamily, ApiError>['data']>;
27
+
28
+ export const fontFamilyRevivers: Revivers<ApiFontFamily, FontFamily> = {
29
+ order: undefined,
30
+ };
31
+
32
+ export async function listFontFamilyFonts(fontFamilyId: number): Promise<Font[]> {
33
+ const pathname = `/v1/fonts/families/${fontFamilyId}/items`;
34
+ const query = getSearchParams({ sort: 'order' });
35
+ const path = `${pathname}?${query}`;
36
+ const options = { revivers: fontRevivers };
37
+
38
+ type ApiFontArray = {
39
+ data: ApiFontData[];
40
+ } & Omit<ApiSuccess, 'data'> | ApiError;
41
+
42
+ return request<ApiFontArray, Font>(path, null, defaultListHeader, options);
43
+ }
@@ -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,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 ADDED
@@ -0,0 +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
+ 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
+ }
@@ -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
+ }