@mapcreator/api 0.0.0-mc2896.0 → 0.0.0-mc2896.2
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.
- package/cjs/api/choropleth.d.ts +42 -29
- package/cjs/api/choropleth.d.ts.map +1 -1
- package/cjs/api/choropleth.js +24 -10
- package/cjs/api/choropleth.js.map +1 -1
- package/cjs/api/insetMap.d.ts.map +1 -1
- package/cjs/api/insetMap.js +14 -3
- package/cjs/api/insetMap.js.map +1 -1
- package/cjs/api/jobRevision.d.ts.map +1 -1
- package/cjs/api/jobRevision.js +14 -3
- package/cjs/api/jobRevision.js.map +1 -1
- package/cjs/api/resources.d.ts +1 -1
- package/cjs/api/resources.d.ts.map +1 -1
- package/cjs/api/resources.js +2 -6
- package/cjs/api/resources.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/cjs/oauth.d.ts +1 -3
- package/cjs/oauth.d.ts.map +1 -1
- package/cjs/oauth.js +2 -9
- package/cjs/oauth.js.map +1 -1
- package/cjs/utils.d.ts +9 -2
- package/cjs/utils.d.ts.map +1 -1
- package/cjs/utils.js +18 -7
- package/cjs/utils.js.map +1 -1
- package/esm/api/choropleth.d.ts +42 -29
- package/esm/api/choropleth.d.ts.map +1 -1
- package/esm/api/choropleth.js +21 -8
- package/esm/api/choropleth.js.map +1 -1
- package/esm/api/insetMap.d.ts.map +1 -1
- package/esm/api/insetMap.js +15 -4
- package/esm/api/insetMap.js.map +1 -1
- package/esm/api/jobRevision.d.ts.map +1 -1
- package/esm/api/jobRevision.js +15 -4
- package/esm/api/jobRevision.js.map +1 -1
- package/esm/api/resources.d.ts +1 -1
- package/esm/api/resources.d.ts.map +1 -1
- package/esm/api/resources.js +2 -6
- package/esm/api/resources.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/oauth.d.ts +1 -3
- package/esm/oauth.d.ts.map +1 -1
- package/esm/oauth.js +2 -9
- package/esm/oauth.js.map +1 -1
- package/esm/utils.d.ts +9 -2
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +18 -9
- package/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/api/choropleth.ts +71 -41
- package/src/api/insetMap.ts +20 -3
- package/src/api/jobRevision.ts +20 -3
- package/src/api/resources.ts +2 -8
- package/src/index.ts +1 -0
- package/src/oauth.ts +4 -12
- package/src/utils.ts +24 -11
package/src/utils.ts
CHANGED
|
@@ -39,12 +39,20 @@ export const staticContext = { keysToRemove: new Set(keysToRemove), keysToAdd: [
|
|
|
39
39
|
export const defaultTimeout = 30000;
|
|
40
40
|
|
|
41
41
|
// class AuthorizationError extends Error {}
|
|
42
|
-
export class NetworkError extends Error {
|
|
42
|
+
export class NetworkError extends Error {
|
|
43
|
+
constructor(error: unknown) {
|
|
44
|
+
super((error as Error)?.message ?? 'Network Error', error instanceof Error ? { cause: error } : {});
|
|
45
|
+
this.name = 'NetworkError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
export class TimeoutError extends Error {
|
|
45
50
|
readonly timeout: number;
|
|
46
|
-
constructor(timeout: number,
|
|
47
|
-
super(
|
|
51
|
+
constructor(timeout: number, error?: unknown) {
|
|
52
|
+
super(
|
|
53
|
+
(error as Error)?.message ?? `Request timed out after ${timeout}ms`,
|
|
54
|
+
error instanceof Error ? { cause: error } : {},
|
|
55
|
+
);
|
|
48
56
|
this.name = 'TimeoutError';
|
|
49
57
|
this.timeout = timeout;
|
|
50
58
|
}
|
|
@@ -54,15 +62,19 @@ export class HTTPError extends Error {
|
|
|
54
62
|
readonly statusCode: number;
|
|
55
63
|
constructor(response: Response) {
|
|
56
64
|
super(response.statusText);
|
|
65
|
+
this.name = 'HTTPError';
|
|
57
66
|
this.statusCode = response.status;
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
export class APIError extends Error {
|
|
62
|
-
readonly code: string;
|
|
71
|
+
readonly code: string | undefined;
|
|
72
|
+
readonly validationErrors: Record<string, string[]> | undefined;
|
|
63
73
|
constructor(apiError: ApiError) {
|
|
64
|
-
super(apiError
|
|
65
|
-
this.
|
|
74
|
+
super(apiError?.error?.message ?? 'API Error');
|
|
75
|
+
this.name = 'APIError';
|
|
76
|
+
this.code = apiError?.error?.type;
|
|
77
|
+
this.validationErrors = apiError?.error?.validation_errors;
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
|
|
@@ -159,10 +171,10 @@ export async function request<
|
|
|
159
171
|
if (error instanceof TimeoutError) throw error;
|
|
160
172
|
|
|
161
173
|
if (error?.name === 'TimeoutError' || error?.name === 'AbortError') {
|
|
162
|
-
throw new TimeoutError(timeout);
|
|
174
|
+
throw new TimeoutError(timeout, error);
|
|
163
175
|
}
|
|
164
176
|
|
|
165
|
-
throw new NetworkError(error
|
|
177
|
+
throw new NetworkError(error);
|
|
166
178
|
})
|
|
167
179
|
.finally(cleanup);
|
|
168
180
|
|
|
@@ -237,6 +249,7 @@ export async function request<
|
|
|
237
249
|
case 403:
|
|
238
250
|
case 404:
|
|
239
251
|
case 406:
|
|
252
|
+
case 422:
|
|
240
253
|
throw new APIError(
|
|
241
254
|
(await response.json().catch(() => ({
|
|
242
255
|
success: false,
|
|
@@ -288,7 +301,7 @@ function getRequestInit<I extends ApiCommon, O extends Record<string, unknown>>(
|
|
|
288
301
|
}
|
|
289
302
|
|
|
290
303
|
const method = extraOptions?.method ?? (body != null ? 'POST' : 'GET'); // don't touch `!=` please
|
|
291
|
-
const authorization = getAuthorizationHeaders(
|
|
304
|
+
const authorization = getAuthorizationHeaders();
|
|
292
305
|
const headers = { Accept: 'application/json', ...authorization, ...contentType, ...extraHeaders };
|
|
293
306
|
|
|
294
307
|
return { body, headers, method, ...!token && { credentials: 'include' } } as RequestInit;
|
|
@@ -334,7 +347,7 @@ export function processData<I extends ApiCommon, O extends Record<string, unknow
|
|
|
334
347
|
return result as O;
|
|
335
348
|
} /* eslint-enable @typescript-eslint/prefer-for-of */
|
|
336
349
|
|
|
337
|
-
function makeTimeoutSignal(timeout: number): { signal: AbortSignal; cleanup: () => void } {
|
|
350
|
+
export function makeTimeoutSignal(timeout: number): { signal: AbortSignal; cleanup: () => void } {
|
|
338
351
|
if (typeof AbortSignal.timeout === 'function') {
|
|
339
352
|
return {
|
|
340
353
|
signal: AbortSignal.timeout(timeout),
|
|
@@ -351,7 +364,7 @@ function makeTimeoutSignal(timeout: number): { signal: AbortSignal; cleanup: ()
|
|
|
351
364
|
}
|
|
352
365
|
}
|
|
353
366
|
|
|
354
|
-
function combineSignals(a: AbortSignal, b: AbortSignal): AbortSignal {
|
|
367
|
+
export function combineSignals(a: AbortSignal, b: AbortSignal): AbortSignal {
|
|
355
368
|
if (typeof AbortSignal.any === 'function') {
|
|
356
369
|
return AbortSignal.any([a, b]);
|
|
357
370
|
} else {
|