@mapcreator/api 0.0.0-saga.1 → 0.0.0-saga.11

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.

Potentially problematic release.


This version of @mapcreator/api might be problematic. Click here for more details.

Files changed (153) hide show
  1. package/cjs/api/apiCommon.d.ts.map +1 -1
  2. package/cjs/api/apiCommon.js +14 -3
  3. package/cjs/api/apiCommon.js.map +1 -1
  4. package/cjs/api/choropleth.d.ts +116 -6
  5. package/cjs/api/choropleth.d.ts.map +1 -1
  6. package/cjs/api/choropleth.js +58 -6
  7. package/cjs/api/choropleth.js.map +1 -1
  8. package/cjs/api/font.d.ts +3 -0
  9. package/cjs/api/font.d.ts.map +1 -1
  10. package/cjs/api/font.js +0 -3
  11. package/cjs/api/font.js.map +1 -1
  12. package/cjs/api/geocode.d.ts +10 -0
  13. package/cjs/api/geocode.d.ts.map +1 -0
  14. package/cjs/api/geocode.js +9 -0
  15. package/cjs/api/geocode.js.map +1 -0
  16. package/cjs/api/highlight.js +1 -1
  17. package/cjs/api/highlight.js.map +1 -1
  18. package/cjs/api/insetMap.d.ts +37 -0
  19. package/cjs/api/insetMap.d.ts.map +1 -0
  20. package/cjs/api/insetMap.js +47 -0
  21. package/cjs/api/insetMap.js.map +1 -0
  22. package/cjs/api/job.d.ts +10 -6
  23. package/cjs/api/job.d.ts.map +1 -1
  24. package/cjs/api/job.js +10 -5
  25. package/cjs/api/job.js.map +1 -1
  26. package/cjs/api/jobResult.d.ts +1 -1
  27. package/cjs/api/jobResult.d.ts.map +1 -1
  28. package/cjs/api/jobResult.js +1 -1
  29. package/cjs/api/jobResult.js.map +1 -1
  30. package/cjs/api/jobRevision.d.ts +3 -3
  31. package/cjs/api/jobRevision.d.ts.map +1 -1
  32. package/cjs/api/jobRevision.js +19 -14
  33. package/cjs/api/jobRevision.js.map +1 -1
  34. package/cjs/api/mapstyleSet.d.ts +2 -1
  35. package/cjs/api/mapstyleSet.d.ts.map +1 -1
  36. package/cjs/api/mapstyleSet.js +9 -0
  37. package/cjs/api/mapstyleSet.js.map +1 -1
  38. package/cjs/api/organisation.d.ts +4 -3
  39. package/cjs/api/organisation.d.ts.map +1 -1
  40. package/cjs/api/organisation.js +6 -7
  41. package/cjs/api/organisation.js.map +1 -1
  42. package/cjs/api/resources.d.ts +7 -1
  43. package/cjs/api/resources.d.ts.map +1 -1
  44. package/cjs/api/resources.js +10 -4
  45. package/cjs/api/resources.js.map +1 -1
  46. package/cjs/api/user.d.ts +2 -1
  47. package/cjs/api/user.d.ts.map +1 -1
  48. package/cjs/api/user.js +4 -5
  49. package/cjs/api/user.js.map +1 -1
  50. package/cjs/index.d.ts +2 -0
  51. package/cjs/index.d.ts.map +1 -1
  52. package/cjs/index.js +2 -0
  53. package/cjs/index.js.map +1 -1
  54. package/cjs/oauth.d.ts +10 -6
  55. package/cjs/oauth.d.ts.map +1 -1
  56. package/cjs/oauth.js +29 -199
  57. package/cjs/oauth.js.map +1 -1
  58. package/cjs/utils.d.ts +9 -2
  59. package/cjs/utils.d.ts.map +1 -1
  60. package/cjs/utils.js +72 -14
  61. package/cjs/utils.js.map +1 -1
  62. package/esm/api/apiCommon.d.ts.map +1 -1
  63. package/esm/api/apiCommon.js +14 -3
  64. package/esm/api/apiCommon.js.map +1 -1
  65. package/esm/api/choropleth.d.ts +116 -6
  66. package/esm/api/choropleth.d.ts.map +1 -1
  67. package/esm/api/choropleth.js +53 -5
  68. package/esm/api/choropleth.js.map +1 -1
  69. package/esm/api/font.d.ts +3 -0
  70. package/esm/api/font.d.ts.map +1 -1
  71. package/esm/api/font.js +1 -4
  72. package/esm/api/font.js.map +1 -1
  73. package/esm/api/geocode.d.ts +10 -0
  74. package/esm/api/geocode.d.ts.map +1 -0
  75. package/esm/api/geocode.js +6 -0
  76. package/esm/api/geocode.js.map +1 -0
  77. package/esm/api/highlight.js +1 -1
  78. package/esm/api/highlight.js.map +1 -1
  79. package/esm/api/insetMap.d.ts +37 -0
  80. package/esm/api/insetMap.d.ts.map +1 -0
  81. package/esm/api/insetMap.js +42 -0
  82. package/esm/api/insetMap.js.map +1 -0
  83. package/esm/api/job.d.ts +10 -6
  84. package/esm/api/job.d.ts.map +1 -1
  85. package/esm/api/job.js +9 -5
  86. package/esm/api/job.js.map +1 -1
  87. package/esm/api/jobResult.d.ts +1 -1
  88. package/esm/api/jobResult.d.ts.map +1 -1
  89. package/esm/api/jobResult.js +1 -1
  90. package/esm/api/jobResult.js.map +1 -1
  91. package/esm/api/jobRevision.d.ts +3 -3
  92. package/esm/api/jobRevision.d.ts.map +1 -1
  93. package/esm/api/jobRevision.js +19 -14
  94. package/esm/api/jobRevision.js.map +1 -1
  95. package/esm/api/mapstyleSet.d.ts +2 -1
  96. package/esm/api/mapstyleSet.d.ts.map +1 -1
  97. package/esm/api/mapstyleSet.js +8 -0
  98. package/esm/api/mapstyleSet.js.map +1 -1
  99. package/esm/api/organisation.d.ts +4 -3
  100. package/esm/api/organisation.d.ts.map +1 -1
  101. package/esm/api/organisation.js +6 -7
  102. package/esm/api/organisation.js.map +1 -1
  103. package/esm/api/resources.d.ts +7 -1
  104. package/esm/api/resources.d.ts.map +1 -1
  105. package/esm/api/resources.js +10 -4
  106. package/esm/api/resources.js.map +1 -1
  107. package/esm/api/user.d.ts +2 -1
  108. package/esm/api/user.d.ts.map +1 -1
  109. package/esm/api/user.js +4 -5
  110. package/esm/api/user.js.map +1 -1
  111. package/esm/index.d.ts +2 -0
  112. package/esm/index.d.ts.map +1 -1
  113. package/esm/index.js +2 -0
  114. package/esm/index.js.map +1 -1
  115. package/esm/oauth.d.ts +10 -6
  116. package/esm/oauth.d.ts.map +1 -1
  117. package/esm/oauth.js +28 -198
  118. package/esm/oauth.js.map +1 -1
  119. package/esm/utils.d.ts +9 -2
  120. package/esm/utils.d.ts.map +1 -1
  121. package/esm/utils.js +71 -14
  122. package/esm/utils.js.map +1 -1
  123. package/package.json +3 -3
  124. package/src/api/apiCommon.ts +71 -70
  125. package/src/api/choropleth.ts +258 -105
  126. package/src/api/color.ts +22 -22
  127. package/src/api/dimension.ts +44 -44
  128. package/src/api/dimensionSet.ts +20 -20
  129. package/src/api/feature.ts +22 -22
  130. package/src/api/font.ts +57 -49
  131. package/src/api/fontFamily.ts +43 -43
  132. package/src/api/geocode.ts +17 -0
  133. package/src/api/highlight.ts +87 -87
  134. package/src/api/insetMap.ts +95 -0
  135. package/src/api/job.ts +139 -129
  136. package/src/api/jobResult.ts +95 -95
  137. package/src/api/jobRevision.ts +281 -278
  138. package/src/api/jobShare.ts +35 -35
  139. package/src/api/jobType.ts +26 -26
  140. package/src/api/language.ts +19 -19
  141. package/src/api/layer.ts +38 -38
  142. package/src/api/layerFaq.ts +53 -53
  143. package/src/api/layerGroup.ts +69 -69
  144. package/src/api/mapstyleSet.ts +70 -48
  145. package/src/api/message.ts +80 -80
  146. package/src/api/organisation.ts +96 -95
  147. package/src/api/resources.ts +153 -143
  148. package/src/api/svg.ts +33 -33
  149. package/src/api/svgSet.ts +56 -56
  150. package/src/api/user.ts +327 -327
  151. package/src/index.ts +44 -42
  152. package/src/oauth.ts +90 -314
  153. package/src/utils.ts +407 -342
@@ -1,20 +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
- };
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
+ };
@@ -1,22 +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
- };
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
+ };
package/src/api/font.ts CHANGED
@@ -1,49 +1,57 @@
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
- };
9
-
10
- export type ApiFont = {
11
- data: {
12
- id: number; // The id of the font (sortable)
13
- font_family_id: number; // The id of the font family
14
- name: string; // The name of the font (searchable, sortable)
15
- style: string; // The font style (searchable, sortable)
16
- stretch: string; // The font stretch (searchable, sortable)
17
- weight: number; // The font weight (searchable, sortable)
18
- label: string; // The label of the font (searchable, sortable)
19
- order?: number; // TODO: not present in API specification!
20
- } & ApiCommonData;
21
- } & Omit<ApiSuccess, 'data'> | ApiError;
22
-
23
- export type ApiFontData = Flatten<Exclude<ApiFont, ApiError>['data']>;
24
-
25
- type FontSearchOptions = {
26
- family?: string;
27
- style?: string;
28
- weight?: string;
29
- };
30
-
31
- export const fontRevivers: Revivers<ApiFont, Font> = {
32
- style: undefined,
33
- stretch: undefined,
34
- weight: 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
- }
1
+ import {
2
+ type ApiCommonData,
3
+ type ApiError,
4
+ type ApiSuccess,
5
+ type Flatten,
6
+ type Revivers,
7
+ getSearchParams,
8
+ request,
9
+ } from '../utils.js';
10
+
11
+ export type Font = {
12
+ id: number;
13
+ fontFamilyId: number;
14
+ name: string;
15
+ label: string;
16
+ weight: number;
17
+ style: string;
18
+ stretch: string;
19
+ };
20
+
21
+ export type ApiFont = {
22
+ data: {
23
+ id: number; // The id of the font (sortable)
24
+ font_family_id: number; // The id of the font family
25
+ name: string; // The name of the font (searchable, sortable)
26
+ style: string; // The font style (searchable, sortable)
27
+ stretch: string; // The font stretch (searchable, sortable)
28
+ weight: number; // The font weight (searchable, sortable)
29
+ label: string; // The label of the font (searchable, sortable)
30
+ order?: number; // TODO: not present in API specification!
31
+ } & ApiCommonData;
32
+ } & Omit<ApiSuccess, 'data'> | ApiError;
33
+
34
+ export type ApiFontData = Flatten<Exclude<ApiFont, ApiError>['data']>;
35
+
36
+ type FontSearchOptions = {
37
+ family?: string;
38
+ style?: string;
39
+ weight?: string;
40
+ };
41
+
42
+ export const fontRevivers: Revivers<ApiFont, Font> = {
43
+ order: undefined,
44
+ };
45
+
46
+ export async function getFonts(searchOptions: FontSearchOptions): Promise<Font[] | Font> {
47
+ const pathname = `/v1/fonts/search`;
48
+ const query = getSearchParams(searchOptions);
49
+
50
+ const path = `${pathname}?${query}`;
51
+
52
+ type ApiFontArray = {
53
+ data: ApiFontData[];
54
+ } & Omit<ApiSuccess, 'data'> | ApiError;
55
+
56
+ return request<ApiFontArray, Font>(path);
57
+ }
@@ -1,43 +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
- }
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,17 @@
1
+ import { type ApiError, type ApiSuccess, request } from '../utils.js';
2
+
3
+ export type GeocodeResult = {
4
+ index: number;
5
+ lat: number | undefined;
6
+ lng: number | undefined;
7
+ };
8
+
9
+ export async function bulkGeocode(addresses: Array<{ index: number; address: string }>): Promise<GeocodeResult[]> {
10
+ const pathname = `/v1/geocode`;
11
+
12
+ type GeocodeResultArray = {
13
+ data: GeocodeResult[];
14
+ } & Omit<ApiSuccess, 'data'> | ApiError;
15
+
16
+ return request<GeocodeResultArray, GeocodeResult>(pathname, { items: addresses });
17
+ }
@@ -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,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
+ }