@mapcreator/api 0.0.0-saga.0 → 0.0.0-saga.10

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 +119 -10
  5. package/cjs/api/choropleth.d.ts.map +1 -1
  6. package/cjs/api/choropleth.js +60 -8
  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 +119 -10
  66. package/esm/api/choropleth.d.ts.map +1 -1
  67. package/esm/api/choropleth.js +54 -6
  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 +256 -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,278 +1,281 @@
1
- import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
2
- import { apiHost, authenticate, token } from '../oauth.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
- | 'png'
23
- | 'jpg'
24
- | 'tiff'
25
- | 'svg'
26
- | 'pdf'
27
- | 'web'
28
- | 'web_download'
29
- | 'webm'
30
- | 'mp4'
31
- | 'mov'
32
- | 'eps'
33
- | 'eps_log'
34
- | 'png_sequence'
35
- | 'jpg_sequence'
36
- | 'mxf';
37
-
38
- export type JobRevision = {
39
- id: number;
40
- jobId: number;
41
- revision: number;
42
- languageCode: string;
43
- mapstyleSetId: number;
44
- output: FileFormat;
45
- };
46
-
47
- export type ApiJobRevision = {
48
- data: {
49
- id: number; // The id of the job revision (sortable)
50
- job_id: number; // The id of the job related to this revision (searchable, sortable)
51
- revision: number; // The revision number (searchable, sortable)
52
- language_code: string; // The language code of the revision (searchable, sortable)
53
- mapstyle_set_id: number; // The id of the mapstyle set
54
- archived: boolean; // Whether the revision has been generated (searchable, sortable)
55
- output: FileFormat; // The output file type
56
- } & ApiCommonData;
57
- } & Omit<ApiSuccess, 'data'> | ApiError;
58
-
59
- export type ApiJobRevisionData = Flatten<Exclude<ApiJobRevision, ApiError>['data']>;
60
-
61
- export const jobRevisionRevivers: Revivers<ApiJobRevision, JobRevision> = {
62
- archived: undefined,
63
- };
64
-
65
- export async function createJobRevision(
66
- jobId: number,
67
- languageCode: string,
68
- mapstyleSetId: number,
69
- layers: number[],
70
- output: FileFormat,
71
- jobObject: Record<string, unknown>,
72
- ): Promise<JobRevision> {
73
- const pathname = `/v1/jobs/${jobId}/revisions`;
74
- const path = `${pathname}?${deletedNoneParam}`;
75
- const body = {
76
- language_code: languageCode,
77
- mapstyle_set_id: mapstyleSetId,
78
- object: JSON.stringify(jobObject),
79
- output,
80
- layers,
81
- };
82
- const options = { revivers: jobRevisionRevivers };
83
-
84
- return request<ApiJobRevision, JobRevision>(path, body, null, options);
85
- }
86
-
87
- export async function getJobRevision(jobId: number): Promise<JobRevision | undefined> {
88
- const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}`;
89
- const options = { revivers: jobRevisionRevivers };
90
-
91
- return request<ApiJobRevision, JobRevision>(path, null, null, options).catch(() => undefined);
92
- }
93
-
94
- export async function getJobRevisionObject<JobObject>(jobId: number): Promise<JobObject> {
95
- const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/object`;
96
- const path = `${pathname}?${deletedNoneParam}`;
97
-
98
- return request<ApiCommon, string>(path).then(JSON.parse) as Promise<JobObject>;
99
- }
100
-
101
- export type JobCanBuild = {
102
- canBuild: boolean;
103
- paymentSource: string;
104
- reason: string | null;
105
- };
106
-
107
- export type ApiJobCanBuild = {
108
- data: {
109
- can_build: boolean;
110
- payment_source: string;
111
- reason: string | null;
112
- } & ApiCommonData;
113
- } & Omit<ApiSuccess, 'data'> | ApiError;
114
-
115
- // Also known as `canBuild()`
116
- export async function getJobRevisionBuild(jobId: number): Promise<JobCanBuild> {
117
- const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build`;
118
- const path = `${pathname}?${deletedNoneParam}`;
119
-
120
- return request<ApiJobCanBuild, JobCanBuild>(path);
121
- }
122
-
123
- export type JobRevisionBuild = {
124
- jobRevisionId: number;
125
- revision: number;
126
- status: string;
127
- };
128
-
129
- export type ApiJobRevisionBuild = {
130
- data: {
131
- job_revision_id: number; // The id of the job revision
132
- status: string; // The status of the job result (searchable, sortable)
133
- contract_id: number; // The id of the contract that was active when the map was created
134
- process_start: string; // The datetime when the job process started (searchable, sortable)
135
- process_end: string; // The datetime when the job process ended (searchable, sortable)
136
- last_downloaded: string; // The last time the archive was downloaded (searchable, sortable)
137
- bought: boolean; // Checks if the result is bought or not (searchable, sortable)
138
- revision: number; // The revision number of the job revision
139
- job_revision: ApiJobRevisionData;
140
- } & ApiCommonData;
141
- } & Omit<ApiSuccess, 'data'> | ApiError;
142
-
143
- export type ApiJobRevisionBuildData = Flatten<Exclude<ApiJobRevisionBuild, ApiError>['data']>;
144
-
145
- export const jobRevisionBuildRevivers: Revivers<ApiJobRevisionBuild, JobRevisionBuild> = {
146
- contract_id: undefined,
147
- process_start: undefined,
148
- process_end: undefined,
149
- last_downloaded: undefined,
150
- bought: undefined,
151
- job_revision: undefined,
152
- };
153
-
154
- export async function registerJobRevisionBuild(
155
- jobId: number,
156
- status: string,
157
- start: Date,
158
- end: Date,
159
- ): Promise<JobRevisionBuild> {
160
- const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build/register`;
161
- const path = `${pathname}?${deletedNoneParam}`;
162
- const body = { status, process_start: start, process_end: end };
163
- const options = { revivers: jobRevisionBuildRevivers };
164
-
165
- return request<ApiJobRevisionBuild, JobRevisionBuild>(path, body, null, options);
166
- }
167
-
168
- export async function cloneJobRevision(jobId: number, newTitle?: string): Promise<JobRevision> {
169
- const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/clone`;
170
- const path = `${pathname}?${deletedNoneParam}`;
171
- const body = { title: newTitle ?? null };
172
- const options = {
173
- revivers: {
174
- ...jobRevisionRevivers,
175
- layers: undefined,
176
- language: undefined,
177
- mapstyle_set: undefined,
178
- },
179
- };
180
-
181
- type ApiJobRevisionWithData = {
182
- data: ApiJobRevisionData & {
183
- layers: ApiLayerData[];
184
- language: ApiLanguageData;
185
- mapstyle_set: ApiMapstyleSetData;
186
- };
187
- } & Omit<ApiSuccess, 'data'> | ApiError;
188
-
189
- return request<ApiJobRevisionWithData, JobRevision>(path, body, null, options);
190
- }
191
-
192
- export async function listJobRevisionLayers(jobId: number): Promise<Layer[]> {
193
- const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/layers`;
194
- const options = { revivers: layerRevivers };
195
-
196
- type ApiLayerArray = {
197
- data: ApiLayerData[];
198
- } & Omit<ApiSuccess, 'data'> | ApiError;
199
-
200
- return request<ApiLayerArray, Layer>(path, null, defaultListHeader, options);
201
- }
202
-
203
- export type JobRevisionOutputUrl = { url: string };
204
-
205
- export type ApiJobRevisionOutputUrl = {
206
- data: JobRevisionOutputUrl & ApiCommonData;
207
- } & Omit<ApiSuccess, 'data'> | ApiError;
208
-
209
- export async function getJobRevisionOutputUrl(jobId: number): Promise<JobRevisionOutputUrl> {
210
- await createJobRevisionBuild(jobId);
211
-
212
- const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/output-url`;
213
-
214
- return request<ApiJobRevisionOutputUrl, JobRevisionOutputUrl>(path);
215
- }
216
-
217
- export type JobRevisionOutput = { blob: Blob; filename?: string | undefined };
218
-
219
- export async function getJobRevisionOutput(jobId: number): Promise<JobRevisionOutput> {
220
- await createJobRevisionBuild(jobId);
221
-
222
- const href = `${apiHost}/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/output`;
223
- const headers = { ...(token ? { Authorization: token.toString() } : null) };
224
- const response = await fetch(href, { headers }).catch((error: Error) => {
225
- throw new NetworkError(error?.message ?? error);
226
- });
227
-
228
- if (response.ok) {
229
- const blob = await response.blob().catch(() => {
230
- throw new APIError({ success: false, error: { type: 'TypeError', message: 'Malformed Blob response' } });
231
- });
232
- const contentDisposition = response.headers.get('Content-Disposition');
233
-
234
- if (contentDisposition) {
235
- const filenameRegex = /filename\*\s*=\s*UTF-8''(.+)/i;
236
- const filenameMatch = contentDisposition.match(filenameRegex);
237
-
238
- if (filenameMatch?.[1]) {
239
- return { blob, filename: filenameMatch[1] };
240
- }
241
-
242
- const fallbackRegex = /filename\s*=\s*"([^"]+)"/i;
243
- const fallbackMatch = contentDisposition.match(fallbackRegex);
244
-
245
- if (fallbackMatch?.[1]) {
246
- return { blob, filename: fallbackMatch[1] };
247
- }
248
- }
249
-
250
- return { blob };
251
- } else {
252
- // eslint-disable-next-line default-case
253
- switch (response.status) {
254
- case 401:
255
- await authenticate();
256
- break; // NO-OP
257
- case 403:
258
- case 404:
259
- case 406:
260
- case 429:
261
- throw new APIError(
262
- (await response.json().catch(() => ({
263
- success: false,
264
- error: { type: 'HttpException', message: response.statusText },
265
- }))) as ApiError,
266
- );
267
- }
268
-
269
- throw new HTTPError(response);
270
- }
271
- }
272
-
273
- async function createJobRevisionBuild(jobId: number): Promise<string> {
274
- const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build`;
275
- const path = `${pathname}?${deletedNoneParam}`;
276
-
277
- return request<ApiCommon, string>(path, null, null, { method: 'POST' });
278
- }
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
+ }
@@ -1,35 +1,35 @@
1
- import { type ApiCommon, type ApiCommonData, type ApiError, type ApiSuccess, type Flatten, request } from '../utils.js';
2
-
3
- export type JobShareVisibility = 'private' | 'organisation' | 'public';
4
-
5
- export type JobShare = {
6
- id: number;
7
- jobId: number;
8
- visibility: JobShareVisibility;
9
- hashKey: string;
10
- apiUrl: string;
11
- webUrl: string;
12
- };
13
-
14
- export type ApiJobShare = {
15
- data: {
16
- id: number; // The id of the job share (sortable)
17
- job_id: number; // The id of the job related to this share
18
- visibility: string; // The visibility of the job share (searchable, sortable)
19
- hash_key: string; // The hash key of the job share
20
- apiUrl: string; // TODO: not present in API specification!
21
- webUrl: string; // TODO: not present in API specification!
22
- } & ApiCommonData;
23
- } & Omit<ApiSuccess, 'data'> | ApiError;
24
-
25
- export type ApiJobShareData = Flatten<Exclude<ApiJobShare, ApiError>['data']>;
26
-
27
- export type ApiJobShareArray = {
28
- data: ApiJobShareData[];
29
- } & Omit<ApiSuccess, 'data'> | ApiError;
30
-
31
- export async function deleteJobShare(jobShareId: number): Promise<Record<string, never>> {
32
- const path = `/v1/jobs/shares/${jobShareId}`;
33
-
34
- return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
35
- }
1
+ import { type ApiCommon, type ApiCommonData, type ApiError, type ApiSuccess, type Flatten, request } from '../utils.js';
2
+
3
+ export type JobShareVisibility = 'private' | 'organisation' | 'public';
4
+
5
+ export type JobShare = {
6
+ id: number;
7
+ jobId: number;
8
+ visibility: JobShareVisibility;
9
+ hashKey: string;
10
+ apiUrl: string;
11
+ webUrl: string;
12
+ };
13
+
14
+ export type ApiJobShare = {
15
+ data: {
16
+ id: number; // The id of the job share (sortable)
17
+ job_id: number; // The id of the job related to this share
18
+ visibility: string; // The visibility of the job share (searchable, sortable)
19
+ hash_key: string; // The hash key of the job share
20
+ apiUrl: string; // TODO: not present in API specification!
21
+ webUrl: string; // TODO: not present in API specification!
22
+ } & ApiCommonData;
23
+ } & Omit<ApiSuccess, 'data'> | ApiError;
24
+
25
+ export type ApiJobShareData = Flatten<Exclude<ApiJobShare, ApiError>['data']>;
26
+
27
+ export type ApiJobShareArray = {
28
+ data: ApiJobShareData[];
29
+ } & Omit<ApiSuccess, 'data'> | ApiError;
30
+
31
+ export async function deleteJobShare(jobShareId: number): Promise<Record<string, never>> {
32
+ const path = `/v1/jobs/shares/${jobShareId}`;
33
+
34
+ return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
35
+ }