@mapcreator/api 0.0.0-saga.1 → 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.
- package/cjs/api/choropleth.d.ts +3 -3
- package/cjs/api/choropleth.d.ts.map +1 -1
- package/cjs/api/choropleth.js +17 -4
- package/cjs/api/choropleth.js.map +1 -1
- package/cjs/api/insetMap.d.ts +37 -0
- package/cjs/api/insetMap.d.ts.map +1 -0
- package/cjs/api/insetMap.js +49 -0
- package/cjs/api/insetMap.js.map +1 -0
- package/cjs/api/job.d.ts +1 -0
- package/cjs/api/job.d.ts.map +1 -1
- package/cjs/api/job.js.map +1 -1
- package/cjs/api/jobResult.d.ts +1 -1
- package/cjs/api/jobResult.d.ts.map +1 -1
- package/cjs/api/jobResult.js +1 -1
- package/cjs/api/jobResult.js.map +1 -1
- package/cjs/api/jobRevision.d.ts +2 -2
- package/cjs/api/jobRevision.d.ts.map +1 -1
- package/cjs/api/jobRevision.js +1 -1
- package/cjs/api/jobRevision.js.map +1 -1
- package/cjs/api/organisation.d.ts +2 -1
- package/cjs/api/organisation.d.ts.map +1 -1
- package/cjs/api/organisation.js +1 -2
- package/cjs/api/organisation.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.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/esm/api/choropleth.d.ts +3 -3
- package/esm/api/choropleth.d.ts.map +1 -1
- package/esm/api/choropleth.js +17 -4
- package/esm/api/choropleth.js.map +1 -1
- package/esm/api/insetMap.d.ts +37 -0
- package/esm/api/insetMap.d.ts.map +1 -0
- package/esm/api/insetMap.js +44 -0
- package/esm/api/insetMap.js.map +1 -0
- package/esm/api/job.d.ts +1 -0
- package/esm/api/job.d.ts.map +1 -1
- package/esm/api/job.js.map +1 -1
- package/esm/api/jobResult.d.ts +1 -1
- package/esm/api/jobResult.d.ts.map +1 -1
- package/esm/api/jobResult.js +1 -1
- package/esm/api/jobResult.js.map +1 -1
- package/esm/api/jobRevision.d.ts +2 -2
- package/esm/api/jobRevision.d.ts.map +1 -1
- package/esm/api/jobRevision.js +1 -1
- package/esm/api/jobRevision.js.map +1 -1
- package/esm/api/organisation.d.ts +2 -1
- package/esm/api/organisation.d.ts.map +1 -1
- package/esm/api/organisation.js +1 -2
- package/esm/api/organisation.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.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/api/apiCommon.ts +70 -70
- package/src/api/choropleth.ts +125 -105
- package/src/api/color.ts +22 -22
- package/src/api/dimension.ts +44 -44
- package/src/api/dimensionSet.ts +20 -20
- package/src/api/feature.ts +22 -22
- package/src/api/font.ts +49 -49
- package/src/api/fontFamily.ts +43 -43
- package/src/api/highlight.ts +87 -87
- package/src/api/insetMap.ts +96 -0
- package/src/api/job.ts +130 -129
- package/src/api/jobResult.ts +95 -95
- package/src/api/jobRevision.ts +279 -278
- package/src/api/jobShare.ts +35 -35
- package/src/api/jobType.ts +26 -26
- package/src/api/language.ts +19 -19
- package/src/api/layer.ts +38 -38
- package/src/api/layerFaq.ts +53 -53
- package/src/api/layerGroup.ts +69 -69
- package/src/api/mapstyleSet.ts +48 -48
- package/src/api/message.ts +80 -80
- package/src/api/organisation.ts +95 -95
- package/src/api/resources.ts +145 -143
- package/src/api/svg.ts +33 -33
- package/src/api/svgSet.ts +56 -56
- package/src/api/user.ts +327 -327
- package/src/index.ts +43 -42
- package/src/oauth.ts +314 -314
- package/src/utils.ts +342 -342
package/src/api/message.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ApiCommon,
|
|
3
|
-
type ApiCommonData,
|
|
4
|
-
type ApiError,
|
|
5
|
-
type ApiSuccess,
|
|
6
|
-
type Flatten,
|
|
7
|
-
type Revivers,
|
|
8
|
-
request,
|
|
9
|
-
} from '../utils.js';
|
|
10
|
-
|
|
11
|
-
export type Message = {
|
|
12
|
-
index: number;
|
|
13
|
-
image: string;
|
|
14
|
-
date: string;
|
|
15
|
-
read: boolean;
|
|
16
|
-
type: 'New feature' | 'Announcement';
|
|
17
|
-
video: boolean;
|
|
18
|
-
title: string;
|
|
19
|
-
text: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type ApiMessageVariant = {
|
|
23
|
-
language_code: string;
|
|
24
|
-
content: string;
|
|
25
|
-
title: string;
|
|
26
|
-
} & ApiCommonData;
|
|
27
|
-
|
|
28
|
-
export type ApiMessage = {
|
|
29
|
-
data: {
|
|
30
|
-
id: number; // The message id (sortable)
|
|
31
|
-
media_url: string; // The media url for this message (searchable, sortable)
|
|
32
|
-
style: string; // TODO: not present in API specification!
|
|
33
|
-
publish_at: string | null; // TODO: not present in API specification!
|
|
34
|
-
ends_at: string | null; // TODO: not present in API specification!
|
|
35
|
-
variants: ApiMessageVariant[];
|
|
36
|
-
} & ApiCommonData;
|
|
37
|
-
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
38
|
-
|
|
39
|
-
export type ApiMessageData = Flatten<Exclude<ApiMessage, ApiError>['data']>;
|
|
40
|
-
|
|
41
|
-
const parseVideo = (url: string, id = getYoutubeVideoId(url)): string =>
|
|
42
|
-
(id ? `https://www.youtube.com/embed/${id}` : url);
|
|
43
|
-
|
|
44
|
-
export const messageRevivers: Revivers<ApiMessage, Message> = {
|
|
45
|
-
id: undefined,
|
|
46
|
-
media_url: undefined,
|
|
47
|
-
style: undefined,
|
|
48
|
-
publish_at: undefined,
|
|
49
|
-
ends_at: undefined,
|
|
50
|
-
variants: undefined,
|
|
51
|
-
|
|
52
|
-
index: (data: ApiMessageData) => data.id,
|
|
53
|
-
image: (data: ApiMessageData) => parseVideo(data.media_url),
|
|
54
|
-
date: (data: ApiMessageData) => data.created_at as string,
|
|
55
|
-
read: () => false,
|
|
56
|
-
type: (data: ApiMessageData) => (data.style === 'regular' ? 'New feature' : 'Announcement'),
|
|
57
|
-
video: (data: ApiMessageData) => data.media_url.includes('www.youtube.com'),
|
|
58
|
-
title: (data: ApiMessageData) => data.variants[0].title,
|
|
59
|
-
text: (data: ApiMessageData) => data.variants[0].content,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export async function markMessageAsRead(messageId: number): Promise<Record<string, never>> {
|
|
63
|
-
const path = `/v1/messages/${messageId}/read`;
|
|
64
|
-
|
|
65
|
-
return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'PUT' });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function getYoutubeVideoId(url: string): string | undefined {
|
|
69
|
-
url = url.trim();
|
|
70
|
-
|
|
71
|
-
// Reference prefixed with a $ or video id
|
|
72
|
-
if (/^\$?[\w\-_]+$/.test(url)) {
|
|
73
|
-
return url;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const regex =
|
|
77
|
-
/(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)&?/;
|
|
78
|
-
|
|
79
|
-
return (regex.exec(url) || [])[1];
|
|
80
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
type ApiCommon,
|
|
3
|
+
type ApiCommonData,
|
|
4
|
+
type ApiError,
|
|
5
|
+
type ApiSuccess,
|
|
6
|
+
type Flatten,
|
|
7
|
+
type Revivers,
|
|
8
|
+
request,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
|
|
11
|
+
export type Message = {
|
|
12
|
+
index: number;
|
|
13
|
+
image: string;
|
|
14
|
+
date: string;
|
|
15
|
+
read: boolean;
|
|
16
|
+
type: 'New feature' | 'Announcement';
|
|
17
|
+
video: boolean;
|
|
18
|
+
title: string;
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type ApiMessageVariant = {
|
|
23
|
+
language_code: string;
|
|
24
|
+
content: string;
|
|
25
|
+
title: string;
|
|
26
|
+
} & ApiCommonData;
|
|
27
|
+
|
|
28
|
+
export type ApiMessage = {
|
|
29
|
+
data: {
|
|
30
|
+
id: number; // The message id (sortable)
|
|
31
|
+
media_url: string; // The media url for this message (searchable, sortable)
|
|
32
|
+
style: string; // TODO: not present in API specification!
|
|
33
|
+
publish_at: string | null; // TODO: not present in API specification!
|
|
34
|
+
ends_at: string | null; // TODO: not present in API specification!
|
|
35
|
+
variants: ApiMessageVariant[];
|
|
36
|
+
} & ApiCommonData;
|
|
37
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
38
|
+
|
|
39
|
+
export type ApiMessageData = Flatten<Exclude<ApiMessage, ApiError>['data']>;
|
|
40
|
+
|
|
41
|
+
const parseVideo = (url: string, id = getYoutubeVideoId(url)): string =>
|
|
42
|
+
(id ? `https://www.youtube.com/embed/${id}` : url);
|
|
43
|
+
|
|
44
|
+
export const messageRevivers: Revivers<ApiMessage, Message> = {
|
|
45
|
+
id: undefined,
|
|
46
|
+
media_url: undefined,
|
|
47
|
+
style: undefined,
|
|
48
|
+
publish_at: undefined,
|
|
49
|
+
ends_at: undefined,
|
|
50
|
+
variants: undefined,
|
|
51
|
+
|
|
52
|
+
index: (data: ApiMessageData) => data.id,
|
|
53
|
+
image: (data: ApiMessageData) => parseVideo(data.media_url),
|
|
54
|
+
date: (data: ApiMessageData) => data.created_at as string,
|
|
55
|
+
read: () => false,
|
|
56
|
+
type: (data: ApiMessageData) => (data.style === 'regular' ? 'New feature' : 'Announcement'),
|
|
57
|
+
video: (data: ApiMessageData) => data.media_url.includes('www.youtube.com'),
|
|
58
|
+
title: (data: ApiMessageData) => data.variants[0].title,
|
|
59
|
+
text: (data: ApiMessageData) => data.variants[0].content,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export async function markMessageAsRead(messageId: number): Promise<Record<string, never>> {
|
|
63
|
+
const path = `/v1/messages/${messageId}/read`;
|
|
64
|
+
|
|
65
|
+
return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'PUT' });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getYoutubeVideoId(url: string): string | undefined {
|
|
69
|
+
url = url.trim();
|
|
70
|
+
|
|
71
|
+
// Reference prefixed with a $ or video id
|
|
72
|
+
if (/^\$?[\w\-_]+$/.test(url)) {
|
|
73
|
+
return url;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const regex =
|
|
77
|
+
/(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)&?/;
|
|
78
|
+
|
|
79
|
+
return (regex.exec(url) || [])[1];
|
|
80
|
+
}
|
package/src/api/organisation.ts
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import type { ApiJobShareArray, JobShare } from './jobShare.js';
|
|
2
|
-
import { type JobSearchResult, listJobs } from './apiCommon.js';
|
|
3
|
-
import {
|
|
4
|
-
type ApiCommonData,
|
|
5
|
-
type ApiError,
|
|
6
|
-
type ApiSuccess,
|
|
7
|
-
type Flatten,
|
|
8
|
-
type Revivers,
|
|
9
|
-
defaultListHeader,
|
|
10
|
-
getSearchParams,
|
|
11
|
-
myOrganisations,
|
|
12
|
-
request,
|
|
13
|
-
} from '../utils.js';
|
|
14
|
-
|
|
15
|
-
export type Organisation = {
|
|
16
|
-
id: number;
|
|
17
|
-
name: string;
|
|
18
|
-
credits: number;
|
|
19
|
-
settings: string | null;
|
|
20
|
-
vectorToken: string;
|
|
21
|
-
trialExpiresAt: string | undefined;
|
|
22
|
-
exportTemplates: string;
|
|
23
|
-
contractType: string;
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type ApiOrganisation = {
|
|
28
|
-
data: {
|
|
29
|
-
id: number; // The id of the organisation (sortable)
|
|
30
|
-
name: string; // The name of the organisation (searchable, sortable)
|
|
31
|
-
manager_id: number; // The id of the manager of the organisation (searchable)
|
|
32
|
-
sales_representative_id: number | null; // The id of the sales representative (searchable)
|
|
33
|
-
credits: number; // The credits of the organisation (searchable, sortable)
|
|
34
|
-
country: string | null; // The country where the organisation is from (searchable, sortable)
|
|
35
|
-
address: string | null; // The address of the organisation (searchable, sortable)
|
|
36
|
-
city: string | null; // The city of the organisation (searchable, sortable)
|
|
37
|
-
settings: string | null; // An object with settings for the organisations
|
|
38
|
-
vector_token: string; // The vector API token of the organisation
|
|
39
|
-
tiles_on_domain: boolean; // TODO: not present in API specification!
|
|
40
|
-
trial_expires_at: string | null; // The datetime when the user's trial expires
|
|
41
|
-
parent_id: number | null; // TODO: not present in API specification!
|
|
42
|
-
hatching_pattern_svg_set_id: number | null; // A svg set that overrides the default h-pattern
|
|
43
|
-
template_settings: string | null; // TODO: not present in API specification!
|
|
44
|
-
contractType: string | null; // The name of signed contract
|
|
45
|
-
|
|
46
|
-
} &
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export async function getOrganisation(): Promise<Organisation> {
|
|
67
|
-
const path = `/v1/organisations/${myOrganisations}`;
|
|
68
|
-
const options = { revivers: organisationRevivers };
|
|
69
|
-
|
|
70
|
-
return request<ApiOrganisation, Organisation>(path, null, null, options);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function listOrganisationJobs(
|
|
74
|
-
organisationId: number | typeof myOrganisations,
|
|
75
|
-
title: string,
|
|
76
|
-
shared: boolean,
|
|
77
|
-
page: number,
|
|
78
|
-
options?: Record<string, unknown>,
|
|
79
|
-
): Promise<JobSearchResult> {
|
|
80
|
-
const search = { ...options, ...{ hidePrivate: true, shared } };
|
|
81
|
-
|
|
82
|
-
return listJobs(`/v1/organisations/${organisationId}/jobs`, title, page, search);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export async function listOrganisationShares(jobId: number): Promise<JobShare[]> {
|
|
86
|
-
const pathname = `/v1/organisations/${myOrganisations}/shares`;
|
|
87
|
-
const query = getSearchParams({
|
|
88
|
-
search: {
|
|
89
|
-
job_id: `=:${jobId}`,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
const path = `${pathname}?${query}`;
|
|
93
|
-
|
|
94
|
-
return request<ApiJobShareArray, JobShare>(path, null, defaultListHeader);
|
|
95
|
-
}
|
|
1
|
+
import type { ApiJobShareArray, JobShare } from './jobShare.js';
|
|
2
|
+
import { type JobSearchResult, listJobs } from './apiCommon.js';
|
|
3
|
+
import {
|
|
4
|
+
type ApiCommonData,
|
|
5
|
+
type ApiError,
|
|
6
|
+
type ApiSuccess,
|
|
7
|
+
type Flatten,
|
|
8
|
+
type Revivers,
|
|
9
|
+
defaultListHeader,
|
|
10
|
+
getSearchParams,
|
|
11
|
+
myOrganisations,
|
|
12
|
+
request,
|
|
13
|
+
} from '../utils.js';
|
|
14
|
+
|
|
15
|
+
export type Organisation = {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
credits: number;
|
|
19
|
+
settings: string | null;
|
|
20
|
+
vectorToken: string;
|
|
21
|
+
trialExpiresAt: string | undefined;
|
|
22
|
+
exportTemplates: string;
|
|
23
|
+
contractType: string;
|
|
24
|
+
subscriptionType: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ApiOrganisation = {
|
|
28
|
+
data: {
|
|
29
|
+
id: number; // The id of the organisation (sortable)
|
|
30
|
+
name: string; // The name of the organisation (searchable, sortable)
|
|
31
|
+
manager_id: number; // The id of the manager of the organisation (searchable)
|
|
32
|
+
sales_representative_id: number | null; // The id of the sales representative (searchable)
|
|
33
|
+
credits: number; // The credits of the organisation (searchable, sortable)
|
|
34
|
+
country: string | null; // The country where the organisation is from (searchable, sortable)
|
|
35
|
+
address: string | null; // The address of the organisation (searchable, sortable)
|
|
36
|
+
city: string | null; // The city of the organisation (searchable, sortable)
|
|
37
|
+
settings: string | null; // An object with settings for the organisations
|
|
38
|
+
vector_token: string; // The vector API token of the organisation
|
|
39
|
+
tiles_on_domain: boolean; // TODO: not present in API specification!
|
|
40
|
+
trial_expires_at: string | null; // The datetime when the user's trial expires
|
|
41
|
+
parent_id: number | null; // TODO: not present in API specification!
|
|
42
|
+
hatching_pattern_svg_set_id: number | null; // A svg set that overrides the default h-pattern
|
|
43
|
+
template_settings: string | null; // TODO: not present in API specification!
|
|
44
|
+
contractType: string | null; // The name of signed contract
|
|
45
|
+
subscriptionType: string | null; // The name of subscription type
|
|
46
|
+
} & ApiCommonData;
|
|
47
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
48
|
+
|
|
49
|
+
export type ApiOrganisationData = Flatten<Exclude<ApiOrganisation, ApiError>['data']>;
|
|
50
|
+
|
|
51
|
+
export const organisationRevivers: Revivers<ApiOrganisation, Organisation> = {
|
|
52
|
+
manager_id: undefined,
|
|
53
|
+
sales_representative_id: undefined,
|
|
54
|
+
country: undefined,
|
|
55
|
+
address: undefined,
|
|
56
|
+
city: undefined,
|
|
57
|
+
tiles_on_domain: undefined,
|
|
58
|
+
parent_id: undefined,
|
|
59
|
+
hatching_pattern_svg_set_id: undefined,
|
|
60
|
+
template_settings: undefined,
|
|
61
|
+
|
|
62
|
+
trialExpiresAt: (data: ApiOrganisationData) => data.trial_expires_at ?? undefined,
|
|
63
|
+
exportTemplates: (data: ApiOrganisationData) => data.template_settings ?? '{}',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export async function getOrganisation(): Promise<Organisation> {
|
|
67
|
+
const path = `/v1/organisations/${myOrganisations}`;
|
|
68
|
+
const options = { revivers: organisationRevivers };
|
|
69
|
+
|
|
70
|
+
return request<ApiOrganisation, Organisation>(path, null, null, options);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function listOrganisationJobs(
|
|
74
|
+
organisationId: number | typeof myOrganisations,
|
|
75
|
+
title: string,
|
|
76
|
+
shared: boolean,
|
|
77
|
+
page: number,
|
|
78
|
+
options?: Record<string, unknown>,
|
|
79
|
+
): Promise<JobSearchResult> {
|
|
80
|
+
const search = { ...options, ...{ hidePrivate: true, shared } };
|
|
81
|
+
|
|
82
|
+
return listJobs(`/v1/organisations/${organisationId}/jobs`, title, page, search);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function listOrganisationShares(jobId: number): Promise<JobShare[]> {
|
|
86
|
+
const pathname = `/v1/organisations/${myOrganisations}/shares`;
|
|
87
|
+
const query = getSearchParams({
|
|
88
|
+
search: {
|
|
89
|
+
job_id: `=:${jobId}`,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
const path = `${pathname}?${query}`;
|
|
93
|
+
|
|
94
|
+
return request<ApiJobShareArray, JobShare>(path, null, defaultListHeader);
|
|
95
|
+
}
|
package/src/api/resources.ts
CHANGED
|
@@ -1,143 +1,145 @@
|
|
|
1
|
-
import { type ApiOrganisationData, type Organisation, organisationRevivers } from './organisation.js';
|
|
2
|
-
import { type ApiDimensionSetData, type DimensionSet, dimensionSetRevivers } from './dimensionSet.js';
|
|
3
|
-
import { type ApiMapstyleSetData, type MapstyleSet, mapstyleSetRevivers } from './mapstyleSet.js';
|
|
4
|
-
import { type ApiDimensionData, type Dimension, dimensionRevivers } from './dimension.js';
|
|
5
|
-
import { type ApiFeatureData, type Feature, featureRevivers } from './feature.js';
|
|
6
|
-
import { type ApiJobTypeData, type JobType, jobTypeRevivers } from './jobType.js';
|
|
7
|
-
import { type ApiMessageData, type Message, messageRevivers } from './message.js';
|
|
8
|
-
import { type ApiSvg, type ApiSvgData, type Svg, svgRevivers } from './svg.js';
|
|
9
|
-
import { type ApiSvgSetData, type SvgSet, svgSetRevivers } from './svgSet.js';
|
|
10
|
-
import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
|
|
11
|
-
import { type ApiColorData, type Color, colorRevivers } from './color.js';
|
|
12
|
-
import { type ApiUserData, type User, userRevivers } from './user.js';
|
|
13
|
-
import type { CamelCasedProperties } from 'type-fest';
|
|
14
|
-
import {
|
|
15
|
-
type ApiCommon,
|
|
16
|
-
type ApiCommonData,
|
|
17
|
-
type ApiError,
|
|
18
|
-
type ApiSuccess,
|
|
19
|
-
type Revivers,
|
|
20
|
-
getContext,
|
|
21
|
-
myUser,
|
|
22
|
-
processData,
|
|
23
|
-
request,
|
|
24
|
-
} from '../utils.js';
|
|
25
|
-
|
|
26
|
-
export type CustomFeature =
|
|
27
|
-
| 'custom_dpi'
|
|
28
|
-
| 'disable_company_maps'
|
|
29
|
-
| 'eps_plus_log'
|
|
30
|
-
| 'filename_is_job_title'
|
|
31
|
-
| 'iframe_sandbox_attributes'
|
|
32
|
-
| 'keep_layer_visibility'
|
|
33
|
-
| 'no_copyright'
|
|
34
|
-
| 'only_shared_company_maps'
|
|
35
|
-
| 'pdf_output'
|
|
36
|
-
| 'show_frelex_links'
|
|
37
|
-
| 'svg_output'
|
|
38
|
-
| 'svg-georef'
|
|
39
|
-
| 'tiff_output'
|
|
40
|
-
| 'video_export'
|
|
41
|
-
| '
|
|
42
|
-
| '
|
|
43
|
-
| '
|
|
44
|
-
| '
|
|
45
|
-
| '
|
|
46
|
-
| '
|
|
47
|
-
| '
|
|
48
|
-
| '
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export type
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
allMessages
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// @ts-expect-error TS2345
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
) as
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
1
|
+
import { type ApiOrganisationData, type Organisation, organisationRevivers } from './organisation.js';
|
|
2
|
+
import { type ApiDimensionSetData, type DimensionSet, dimensionSetRevivers } from './dimensionSet.js';
|
|
3
|
+
import { type ApiMapstyleSetData, type MapstyleSet, mapstyleSetRevivers } from './mapstyleSet.js';
|
|
4
|
+
import { type ApiDimensionData, type Dimension, dimensionRevivers } from './dimension.js';
|
|
5
|
+
import { type ApiFeatureData, type Feature, featureRevivers } from './feature.js';
|
|
6
|
+
import { type ApiJobTypeData, type JobType, jobTypeRevivers } from './jobType.js';
|
|
7
|
+
import { type ApiMessageData, type Message, messageRevivers } from './message.js';
|
|
8
|
+
import { type ApiSvg, type ApiSvgData, type Svg, svgRevivers } from './svg.js';
|
|
9
|
+
import { type ApiSvgSetData, type SvgSet, svgSetRevivers } from './svgSet.js';
|
|
10
|
+
import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
|
|
11
|
+
import { type ApiColorData, type Color, colorRevivers } from './color.js';
|
|
12
|
+
import { type ApiUserData, type User, userRevivers } from './user.js';
|
|
13
|
+
import type { CamelCasedProperties } from 'type-fest';
|
|
14
|
+
import {
|
|
15
|
+
type ApiCommon,
|
|
16
|
+
type ApiCommonData,
|
|
17
|
+
type ApiError,
|
|
18
|
+
type ApiSuccess,
|
|
19
|
+
type Revivers,
|
|
20
|
+
getContext,
|
|
21
|
+
myUser,
|
|
22
|
+
processData,
|
|
23
|
+
request,
|
|
24
|
+
} from '../utils.js';
|
|
25
|
+
|
|
26
|
+
export type CustomFeature =
|
|
27
|
+
| 'custom_dpi'
|
|
28
|
+
| 'disable_company_maps'
|
|
29
|
+
| 'eps_plus_log'
|
|
30
|
+
| 'filename_is_job_title'
|
|
31
|
+
| 'iframe_sandbox_attributes'
|
|
32
|
+
| 'keep_layer_visibility'
|
|
33
|
+
| 'no_copyright'
|
|
34
|
+
| 'only_shared_company_maps'
|
|
35
|
+
| 'pdf_output'
|
|
36
|
+
| 'show_frelex_links'
|
|
37
|
+
| 'svg_output'
|
|
38
|
+
| 'svg-georef'
|
|
39
|
+
| 'tiff_output'
|
|
40
|
+
| 'video_export'
|
|
41
|
+
| 'v5_video'
|
|
42
|
+
| 'web_output'
|
|
43
|
+
| 'web_download'
|
|
44
|
+
| 'new_single_and_grouped_areas_menu'
|
|
45
|
+
| 'export_templates'
|
|
46
|
+
| 'export_video_tracking_data'
|
|
47
|
+
| 'hosted_svg_output'
|
|
48
|
+
| 'hosted_png_output'
|
|
49
|
+
| 'hosted_jpg_output'
|
|
50
|
+
| 'developer_menu';
|
|
51
|
+
|
|
52
|
+
export interface Resources {
|
|
53
|
+
organisation: Organisation;
|
|
54
|
+
user: User;
|
|
55
|
+
features: CustomFeature[];
|
|
56
|
+
colors: Color[];
|
|
57
|
+
svgs: Svg[];
|
|
58
|
+
dimensions: Dimension[];
|
|
59
|
+
dimensionSets: DimensionSet[];
|
|
60
|
+
mapstyleSets: MapstyleSet[];
|
|
61
|
+
jobTypes: JobType[];
|
|
62
|
+
messages: Message[];
|
|
63
|
+
svgSets: SvgSet[];
|
|
64
|
+
layers: Layer[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type ApiResources = {
|
|
68
|
+
data: {
|
|
69
|
+
user: ApiUserData;
|
|
70
|
+
organisation: ApiOrganisationData;
|
|
71
|
+
features: ApiFeatureData[];
|
|
72
|
+
colors: ApiColorData[];
|
|
73
|
+
svgs: ApiSvgData[];
|
|
74
|
+
messages: {
|
|
75
|
+
read: ApiMessageData[];
|
|
76
|
+
unread: ApiMessageData[];
|
|
77
|
+
};
|
|
78
|
+
dimensions: ApiDimensionData[];
|
|
79
|
+
dimension_sets: ApiDimensionSetData[];
|
|
80
|
+
mapstyle_sets: ApiMapstyleSetData[];
|
|
81
|
+
hatching_svgs?: ApiSvgData[];
|
|
82
|
+
job_types: ApiJobTypeData[];
|
|
83
|
+
svg_sets: ApiSvgSetData[];
|
|
84
|
+
layers: ApiLayerData[];
|
|
85
|
+
} & ApiCommonData;
|
|
86
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
87
|
+
|
|
88
|
+
export type ApiResourcesData = Exclude<ApiResources, ApiError>['data'];
|
|
89
|
+
|
|
90
|
+
export type FillPattern = {
|
|
91
|
+
name: string;
|
|
92
|
+
string: string;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export async function loadResources(): Promise<Resources> {
|
|
96
|
+
const path = `/v1/users/${myUser}/resources`;
|
|
97
|
+
const raw = await request<ApiResources, CamelCasedProperties<ApiResourcesData>>(path);
|
|
98
|
+
|
|
99
|
+
const { user, organisation, messages: { read, unread } } = raw;
|
|
100
|
+
const readMessages = read.map(processData, getContext(messageRevivers)) as Message[];
|
|
101
|
+
const unreadMessages = unread.map(processData, getContext(messageRevivers)) as Message[];
|
|
102
|
+
|
|
103
|
+
readMessages.forEach(message => (message.read = true));
|
|
104
|
+
|
|
105
|
+
const allMessages = [...readMessages, ...unreadMessages];
|
|
106
|
+
|
|
107
|
+
allMessages.sort((m1, m2) => m2.date.localeCompare(m1.date));
|
|
108
|
+
|
|
109
|
+
const mcSvgRevivers: Revivers<ApiSvg, Svg> = {
|
|
110
|
+
...svgRevivers,
|
|
111
|
+
name: (data: ApiSvgData) => `mc-image-${data.name}`,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
// @ts-expect-error TS2345
|
|
116
|
+
user: processData.call(getContext(userRevivers), user) as User,
|
|
117
|
+
// @ts-expect-error TS2345
|
|
118
|
+
organisation: processData.call(getContext(organisationRevivers), organisation) as Organisation,
|
|
119
|
+
|
|
120
|
+
features: (raw.features.map(processData, getContext(featureRevivers)) as Feature[]).map(
|
|
121
|
+
feature => feature.name,
|
|
122
|
+
) as CustomFeature[],
|
|
123
|
+
colors: raw.colors.map(processData, getContext(colorRevivers)) as Color[],
|
|
124
|
+
svgs: raw.svgs.map(processData, getContext(mcSvgRevivers)) as Svg[],
|
|
125
|
+
dimensions: raw.dimensions.map(processData, getContext(dimensionRevivers)) as Dimension[],
|
|
126
|
+
dimensionSets: raw.dimensionSets.map(processData, getContext(dimensionSetRevivers)) as DimensionSet[],
|
|
127
|
+
mapstyleSets: raw.mapstyleSets.map(processData, getContext(mapstyleSetRevivers)) as MapstyleSet[],
|
|
128
|
+
jobTypes: raw.jobTypes.map(processData, getContext(jobTypeRevivers)) as JobType[],
|
|
129
|
+
messages: allMessages,
|
|
130
|
+
layers: (raw.layers?.map(processData, getContext(layerRevivers)) ?? []) as Layer[],
|
|
131
|
+
svgSets: (raw.svgSets?.map(processData, getContext(svgSetRevivers)) ?? []) as SvgSet[],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function getCountries(): Promise<string[]> {
|
|
136
|
+
return request<ApiCommon, string, true>(`/v1/resources/countries`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function getFunctions(): Promise<string[]> {
|
|
140
|
+
return request<ApiCommon, string, true>(`/v1/resources/functions`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function getIndustries(): Promise<string[]> {
|
|
144
|
+
return request<ApiCommon, string, true>(`/v1/resources/industries`);
|
|
145
|
+
}
|