@mapcreator/api 0.0.0-saga.2 → 0.0.0-saga.3

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