@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,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
+ }
@@ -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
- hasContract: boolean;
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
- } & ApiCommonData;
46
- } & Omit<ApiSuccess, 'data'> | ApiError;
47
-
48
- export type ApiOrganisationData = Flatten<Exclude<ApiOrganisation, ApiError>['data']>;
49
-
50
- export const organisationRevivers: Revivers<ApiOrganisation, Organisation> = {
51
- manager_id: undefined,
52
- sales_representative_id: undefined,
53
- country: undefined,
54
- address: undefined,
55
- city: undefined,
56
- tiles_on_domain: undefined,
57
- parent_id: undefined,
58
- hatching_pattern_svg_set_id: undefined,
59
- template_settings: undefined,
60
-
61
- trialExpiresAt: (data: ApiOrganisationData) => data.trial_expires_at ?? undefined,
62
- exportTemplates: (data: ApiOrganisationData) => data.template_settings ?? '{}', // @ts-expect-error TS2551
63
- hasContract: (data: ApiOrganisationData) => !!(data.contractType ?? data.contract_type ?? data.hasContract),
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
+ }
@@ -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
- | 'web_output'
42
- | 'web_download'
43
- | 'new_single_and_grouped_areas_menu'
44
- | 'export_templates'
45
- | 'hosted_svg_output'
46
- | 'hosted_png_output'
47
- | 'hosted_jpg_output'
48
- | 'developer_menu';
49
-
50
- export interface Resources {
51
- organisation: Organisation;
52
- user: User;
53
- features: CustomFeature[];
54
- colors: Color[];
55
- svgs: Svg[];
56
- dimensions: Dimension[];
57
- dimensionSets: DimensionSet[];
58
- mapstyleSets: MapstyleSet[];
59
- jobTypes: JobType[];
60
- messages: Message[];
61
- svgSets: SvgSet[];
62
- layers: Layer[];
63
- }
64
-
65
- type ApiResources = {
66
- data: {
67
- user: ApiUserData;
68
- organisation: ApiOrganisationData;
69
- features: ApiFeatureData[];
70
- colors: ApiColorData[];
71
- svgs: ApiSvgData[];
72
- messages: {
73
- read: ApiMessageData[];
74
- unread: ApiMessageData[];
75
- };
76
- dimensions: ApiDimensionData[];
77
- dimension_sets: ApiDimensionSetData[];
78
- mapstyle_sets: ApiMapstyleSetData[];
79
- hatching_svgs?: ApiSvgData[];
80
- job_types: ApiJobTypeData[];
81
- svg_sets: ApiSvgSetData[];
82
- layers: ApiLayerData[];
83
- } & ApiCommonData;
84
- } & Omit<ApiSuccess, 'data'> | ApiError;
85
-
86
- export type ApiResourcesData = Exclude<ApiResources, ApiError>['data'];
87
-
88
- export type FillPattern = {
89
- name: string;
90
- string: string;
91
- };
92
-
93
- export async function loadResources(): Promise<Resources> {
94
- const path = `/v1/users/${myUser}/resources`;
95
- const raw = await request<ApiResources, CamelCasedProperties<ApiResourcesData>>(path);
96
-
97
- const { user, organisation, messages: { read, unread } } = raw;
98
- const readMessages = read.map(processData, getContext(messageRevivers)) as Message[];
99
- const unreadMessages = unread.map(processData, getContext(messageRevivers)) as Message[];
100
-
101
- readMessages.forEach(message => (message.read = true));
102
-
103
- const allMessages = [...readMessages, ...unreadMessages];
104
-
105
- allMessages.sort((m1, m2) => m2.date.localeCompare(m1.date));
106
-
107
- const mcSvgRevivers: Revivers<ApiSvg, Svg> = {
108
- ...svgRevivers,
109
- name: (data: ApiSvgData) => `mc-image-${data.name}`,
110
- };
111
-
112
- return {
113
- // @ts-expect-error TS2345
114
- user: processData.call(getContext(userRevivers), user) as User,
115
- // @ts-expect-error TS2345
116
- organisation: processData.call(getContext(organisationRevivers), organisation) as Organisation,
117
-
118
- features: (raw.features.map(processData, getContext(featureRevivers)) as Feature[]).map(
119
- feature => feature.name,
120
- ) as CustomFeature[],
121
- colors: raw.colors.map(processData, getContext(colorRevivers)) as Color[],
122
- svgs: raw.svgs.map(processData, getContext(mcSvgRevivers)) as Svg[],
123
- dimensions: raw.dimensions.map(processData, getContext(dimensionRevivers)) as Dimension[],
124
- dimensionSets: raw.dimensionSets.map(processData, getContext(dimensionSetRevivers)) as DimensionSet[],
125
- mapstyleSets: raw.mapstyleSets.map(processData, getContext(mapstyleSetRevivers)) as MapstyleSet[],
126
- jobTypes: raw.jobTypes.map(processData, getContext(jobTypeRevivers)) as JobType[],
127
- messages: allMessages,
128
- layers: (raw.layers?.map(processData, getContext(layerRevivers)) ?? []) as Layer[],
129
- svgSets: (raw.svgSets?.map(processData, getContext(svgSetRevivers)) ?? []) as SvgSet[],
130
- };
131
- }
132
-
133
- export async function getCountries(): Promise<string[]> {
134
- return request<ApiCommon, string, true>(`/v1/resources/countries`);
135
- }
136
-
137
- export async function getFunctions(): Promise<string[]> {
138
- return request<ApiCommon, string, true>(`/v1/resources/functions`);
139
- }
140
-
141
- export async function getIndustries(): Promise<string[]> {
142
- return request<ApiCommon, string, true>(`/v1/resources/industries`);
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
+ }