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

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 +8 -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 +8 -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 +126 -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
package/src/api/user.ts CHANGED
@@ -1,327 +1,327 @@
1
- import { type ApiFontFamilyData, type FontFamily, fontFamilyRevivers } from './fontFamily.js';
2
- import { type ApiSvgSetData, type SvgSet, svgSetRevivers } from './svgSet.js';
3
- import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
4
- import { type ApiSvgData, type Svg, svgRevivers } from './svg.js';
5
- import { type JobSearchResult, listJobs } from './apiCommon.js';
6
- import type { ApiJobShareArray, JobShare } from './jobShare.js';
7
- import type { RequireAtLeastOne } from 'type-fest';
8
- import {
9
- type ApiCommon,
10
- type ApiCommonData,
11
- type ApiError,
12
- type ApiSuccess,
13
- type Flatten,
14
- type Revivers,
15
- defaultListHeader,
16
- deletedNoneParam,
17
- getSearchParams,
18
- myUser,
19
- request,
20
- toApiType,
21
- } from '../utils.js';
22
-
23
- type ApiPermission = {
24
- id: number; // The id of the permission
25
- name: string; // The name of the permission (searchable, sortable)
26
- } & ApiCommonData;
27
-
28
- type ApiRole = {
29
- id: number;
30
- name: string;
31
- description: string;
32
- pivot: {
33
- model_type: string;
34
- model_id: number;
35
- role_id: number;
36
- };
37
- } & ApiCommonData;
38
-
39
- type UnitType = 'metric' | 'imperial' | null;
40
-
41
- export type User = {
42
- id: number;
43
- languageCode: string;
44
- interfaceLanguage: string;
45
- videoNotifications: boolean;
46
- name: string;
47
- email: string;
48
- company: string;
49
- confirmed: boolean;
50
- propagated: boolean;
51
- whatsNewBadge: boolean;
52
- autosave: boolean;
53
- unit: UnitType;
54
- trialExpiresAt: string | undefined;
55
- stripeId: string | undefined;
56
- intercomIdentityToken?: string;
57
- hasPassword?: boolean;
58
- };
59
- /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
60
- export type ApiUser = {
61
- data: {
62
- id: number; // The id of the user (searchable, sortable)
63
- organisation_id: number; // The id of the organisation related to a user (searchable)
64
- language_code: string; // The default map language
65
- interface_language: string; // The default interface language
66
- hide_messages: boolean; // If the what's new notifications should be shown
67
- video_notifications: boolean; // TODO: not present in API specification!
68
- name: string; // The name of the user (searchable, sortable)
69
- email: string; // The email of the user (searchable, sortable)
70
- phone: string | null; // The phone of the user (searchable, sortable)
71
- profession: string | null; // The user's profession (searchable, sortable)
72
- company: string | null; // The user's company (sortable)
73
- country: string | null; // The user's country (sortable)
74
- city: string | null; // The user's city (sortable)
75
- address: string | null; // The user's address (sortable)
76
- tips: boolean; // If the user wishes to see tips
77
- tags: string[] | null; // The tags related to a user (searchable, sortable)
78
- confirmed: boolean; // Whether the user email is verified
79
- propagated: boolean; // Set to 'true' on the first user login (hubspot)
80
- newsletter_consent: boolean; // TODO: not present in API specification!
81
- whats_new_badge: boolean; // If the what's new notifications should be shown
82
- autosave: boolean; // If the tool should autosave projects
83
- unit: UnitType; // Default measurement unit type
84
- registration_complete: boolean; // Whether the user has completed their registration
85
- notifications_checked_at: string | null; // The datetime when the user checked the notifications
86
- referral: string | null; // The referral code that the user used during their registration
87
- trial_expires_at: string | null; // The datetime when the user's trial expires
88
- delete_requested: boolean | null; // TODO: not present in API specification!
89
- delete_request_notified: number; // TODO: not present in API specification!
90
- stripe_id: string | null; // TODO: not present in API specification!
91
- stripe_ref: unknown | null; // TODO: not present in API specification!
92
- pm_type: unknown | null; // TODO: not present in API specification!
93
- pm_last_four: unknown | null; // TODO: not present in API specification!
94
- trial_ends_at: string | null; // TODO: not present in API specification!
95
- settings: string | null; // TODO: not present in API specification!
96
- intercom_identity_token?: string; // [resources endpoint only] Helpdesk token
97
- has_password?: boolean; // [resources endpoint only] SSO or not (enables an ability to change the email)
98
- permissions: ApiPermission[]; // TODO: not present in API specification!
99
- roles: ApiRole[]; // TODO: not present in API specification!
100
- } & ApiCommonData;
101
- } & Omit<ApiSuccess, 'data'> | ApiError;
102
- /* eslint-enable @typescript-eslint/no-redundant-type-constituents */
103
- export type ApiUserData = Flatten<Exclude<ApiUser, ApiError>['data']>;
104
-
105
- export type JobFolder = {
106
- id: number;
107
- jobsCount: number;
108
- name: string;
109
- userId: number;
110
- };
111
-
112
- export type ApiJobFolder = {
113
- data: {
114
- id: number;
115
- jobsCount: number;
116
- name: string;
117
- userId: number;
118
- } & ApiCommonData;
119
- } & Omit<ApiSuccess, 'data'> | ApiError;
120
-
121
- export type ApiJobFolderData = Flatten<Exclude<ApiJobFolder, ApiError>['data']>;
122
-
123
- export const userRevivers: Revivers<ApiUser, User> = {
124
- organisation_id: undefined,
125
- hide_messages: undefined,
126
- phone: undefined,
127
- profession: undefined,
128
- country: undefined,
129
- city: undefined,
130
- address: undefined,
131
- tips: undefined,
132
- tags: undefined,
133
- newsletter_consent: undefined,
134
- registration_complete: undefined,
135
- notifications_checked_at: undefined,
136
- referral: undefined,
137
- delete_requested: undefined,
138
- delete_request_notified: undefined,
139
- stripe_ref: undefined,
140
- pm_type: undefined,
141
- pm_last_four: undefined,
142
- trial_ends_at: undefined,
143
- settings: undefined,
144
- permissions: undefined,
145
- roles: undefined,
146
-
147
- trialExpiresAt: (data: ApiUserData) => data.trial_expires_at ?? undefined,
148
- stripeId: (data: ApiUserData) => data.stripe_id ?? undefined,
149
- };
150
-
151
- type UpdateUserParams = {
152
- whatsNewBadge?: boolean;
153
- videoNotifications?: boolean;
154
- autosave?: boolean;
155
- interfaceLanguage?: string;
156
- languageCode?: string;
157
- unit?: UnitType;
158
- password?: string;
159
- email?: string;
160
- };
161
-
162
- export async function getUser(): Promise<User> {
163
- const path = `/v1/users/${myUser}`;
164
- const options = { revivers: userRevivers };
165
-
166
- return request<ApiUser, User>(path, null, null, options);
167
- }
168
-
169
- export async function updateUser(
170
- userId: number | typeof myUser,
171
- fields: RequireAtLeastOne<UpdateUserParams>,
172
- ): Promise<Record<string, never>> {
173
- const path = `/v1/users/${userId}`;
174
- const body = toApiType(fields);
175
-
176
- return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
177
- }
178
-
179
- export async function deleteUser(userId: number | typeof myUser): Promise<Record<string, never>> {
180
- const path = `/v1/users/${userId}`;
181
-
182
- return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
183
- }
184
-
185
- export async function listUserFontFamilies(): Promise<FontFamily[]> {
186
- const pathname = `/v1/users/${myUser}/font-families`;
187
- const query = getSearchParams({ sort: 'order' });
188
- const path = `${pathname}?${query}`;
189
- const options = { revivers: fontFamilyRevivers };
190
-
191
- type ApiFontFamilyArray = {
192
- data: ApiFontFamilyData[];
193
- } & Omit<ApiSuccess, 'data'> | ApiError;
194
-
195
- return request<ApiFontFamilyArray, FontFamily>(path, null, defaultListHeader, options);
196
- }
197
-
198
- export async function listUserHatchingSvgs(): Promise<Svg[]> {
199
- const pathname = `/v1/users/${myUser}/hatching-svgs`;
200
- const query = getSearchParams({ sort: 'order' });
201
- const path = `${pathname}?${query}`;
202
- const options = { revivers: svgRevivers };
203
-
204
- type ApiSvgArray = {
205
- data: ApiSvgData[];
206
- } & Omit<ApiSuccess, 'data'> | ApiError;
207
-
208
- return request<ApiSvgArray, Svg>(path, null, defaultListHeader, options);
209
- }
210
-
211
- export async function listUserJobs(
212
- userId: number | typeof myUser,
213
- title: string,
214
- page: number,
215
- options?: Record<string, unknown>
216
- ): Promise<JobSearchResult> {
217
- return listJobs(`/v1/users/${userId}/jobs`, title, page, options);
218
- }
219
-
220
- export async function listUserFolders(): Promise<JobFolder[]> {
221
- const path = `/v1/users/${myUser}/folders`;
222
-
223
- type ApiJobFolderArray = {
224
- data: ApiJobFolderData[];
225
- } & Omit<ApiSuccess, 'data'> | ApiError;
226
-
227
- return request<ApiJobFolderArray, JobFolder>(path);
228
- }
229
-
230
- export async function createUserFolder(name: string): Promise<JobFolder> {
231
- const path = `/v1/users/${myUser}/folders`;
232
- const body = { name };
233
-
234
- return request<ApiCommon, JobFolder>(path, body);
235
- }
236
-
237
- export async function deleteUserFolder(folderId: number): Promise<Record<string, never>> {
238
- const path = `/v1/users/${myUser}/folders/${folderId}`;
239
-
240
- return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
241
- }
242
-
243
- export async function renameUserFolder(folderId: number, name: string): Promise<Record<string, never>> {
244
- const path = `/v1/users/${myUser}/folders/${folderId}`;
245
- const body = { name };
246
-
247
- return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
248
- }
249
-
250
- export async function listUserLayers(): Promise<Layer[]> {
251
- const pathname = `/v1/users/${myUser}/layers`;
252
- const query = getSearchParams({
253
- search: {
254
- pangaea_ready: '1',
255
- },
256
- sort: 'order',
257
- });
258
- const path = `${pathname}?${query}`;
259
- const options = { revivers: layerRevivers };
260
-
261
- type ApiLayerArray = {
262
- data: ApiLayerData[];
263
- } & Omit<ApiSuccess, 'data'> | ApiError;
264
-
265
- return request<ApiLayerArray, Layer>(path, null, defaultListHeader, options);
266
- }
267
-
268
- export async function listUserSvgSets(): Promise<SvgSet[]> {
269
- const pathname = `/v1/users/${myUser}/svg-sets`;
270
- const query = getSearchParams({
271
- search: {
272
- supports_mapcreator: '1',
273
- type: '!:sprite',
274
- },
275
- sort: 'order',
276
- });
277
- const path = `${pathname}?${query}`;
278
- const options = { revivers: svgSetRevivers };
279
-
280
- type ApiSvgSetArray = {
281
- data: ApiSvgSetData[];
282
- } & Omit<ApiSuccess, 'data'> | ApiError;
283
-
284
- return request<ApiSvgSetArray, SvgSet>(path, null, defaultListHeader, options);
285
- }
286
-
287
- export async function findJobShares(jobId: number): Promise<JobShare[]> {
288
- const pathname = `/v1/users/${myUser}/job-shares`;
289
- const query = getSearchParams({ search: { job_id: jobId } });
290
- const path = `${pathname}?${query}`;
291
-
292
- return request<ApiJobShareArray, JobShare>(path);
293
- }
294
-
295
- export async function createUserTrial(
296
- userId: number | typeof myUser,
297
- data: Record<string, unknown>,
298
- ): Promise<Record<string, never>> {
299
- const pathname = `/v1/users/${userId}/trial`;
300
- const path = `${pathname}?${deletedNoneParam}`;
301
- const body = toApiType(data);
302
-
303
- return request<ApiCommon, Record<string, never>>(path, body);
304
- }
305
-
306
- export async function sendUserConfirmationEmail(userId: number | typeof myUser): Promise<Record<string, never>> {
307
- const path = `/v1/users/${userId}/confirm`;
308
-
309
- return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'POST' });
310
- }
311
-
312
- type BillingPortal = {
313
- billingPortalUrl: string;
314
- };
315
- type ApiBillingPortal = {
316
- data: {
317
- billing_portal_url: string;
318
- };
319
- } & Omit<ApiSuccess, 'data'> | ApiError;
320
-
321
- export async function getUserBillingPortalUrl(userId: number | typeof myUser): Promise<string> {
322
- const path = `/v1/users/${userId}/billing-portal-url`;
323
-
324
- return request<ApiBillingPortal, BillingPortal>(path).then(
325
- ({ billingPortalUrl }) => billingPortalUrl,
326
- );
327
- }
1
+ import { type ApiFontFamilyData, type FontFamily, fontFamilyRevivers } from './fontFamily.js';
2
+ import { type ApiSvgSetData, type SvgSet, svgSetRevivers } from './svgSet.js';
3
+ import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
4
+ import { type ApiSvgData, type Svg, svgRevivers } from './svg.js';
5
+ import { type JobSearchResult, listJobs } from './apiCommon.js';
6
+ import type { ApiJobShareArray, JobShare } from './jobShare.js';
7
+ import type { RequireAtLeastOne } from 'type-fest';
8
+ import {
9
+ type ApiCommon,
10
+ type ApiCommonData,
11
+ type ApiError,
12
+ type ApiSuccess,
13
+ type Flatten,
14
+ type Revivers,
15
+ defaultListHeader,
16
+ deletedNoneParam,
17
+ getSearchParams,
18
+ myUser,
19
+ request,
20
+ toApiType,
21
+ } from '../utils.js';
22
+
23
+ type ApiPermission = {
24
+ id: number; // The id of the permission
25
+ name: string; // The name of the permission (searchable, sortable)
26
+ } & ApiCommonData;
27
+
28
+ type ApiRole = {
29
+ id: number;
30
+ name: string;
31
+ description: string;
32
+ pivot: {
33
+ model_type: string;
34
+ model_id: number;
35
+ role_id: number;
36
+ };
37
+ } & ApiCommonData;
38
+
39
+ type UnitType = 'metric' | 'imperial' | null;
40
+
41
+ export type User = {
42
+ id: number;
43
+ languageCode: string;
44
+ interfaceLanguage: string;
45
+ videoNotifications: boolean;
46
+ name: string;
47
+ email: string;
48
+ company: string;
49
+ confirmed: boolean;
50
+ propagated: boolean;
51
+ whatsNewBadge: boolean;
52
+ autosave: boolean;
53
+ unit: UnitType;
54
+ trialExpiresAt: string | undefined;
55
+ stripeId: string | undefined;
56
+ intercomIdentityToken?: string;
57
+ hasPassword?: boolean;
58
+ };
59
+ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
60
+ export type ApiUser = {
61
+ data: {
62
+ id: number; // The id of the user (searchable, sortable)
63
+ organisation_id: number; // The id of the organisation related to a user (searchable)
64
+ language_code: string; // The default map language
65
+ interface_language: string; // The default interface language
66
+ hide_messages: boolean; // If the what's new notifications should be shown
67
+ video_notifications: boolean; // TODO: not present in API specification!
68
+ name: string; // The name of the user (searchable, sortable)
69
+ email: string; // The email of the user (searchable, sortable)
70
+ phone: string | null; // The phone of the user (searchable, sortable)
71
+ profession: string | null; // The user's profession (searchable, sortable)
72
+ company: string | null; // The user's company (sortable)
73
+ country: string | null; // The user's country (sortable)
74
+ city: string | null; // The user's city (sortable)
75
+ address: string | null; // The user's address (sortable)
76
+ tips: boolean; // If the user wishes to see tips
77
+ tags: string[] | null; // The tags related to a user (searchable, sortable)
78
+ confirmed: boolean; // Whether the user email is verified
79
+ propagated: boolean; // Set to 'true' on the first user login (hubspot)
80
+ newsletter_consent: boolean; // TODO: not present in API specification!
81
+ whats_new_badge: boolean; // If the what's new notifications should be shown
82
+ autosave: boolean; // If the tool should autosave projects
83
+ unit: UnitType; // Default measurement unit type
84
+ registration_complete: boolean; // Whether the user has completed their registration
85
+ notifications_checked_at: string | null; // The datetime when the user checked the notifications
86
+ referral: string | null; // The referral code that the user used during their registration
87
+ trial_expires_at: string | null; // The datetime when the user's trial expires
88
+ delete_requested: boolean | null; // TODO: not present in API specification!
89
+ delete_request_notified: number; // TODO: not present in API specification!
90
+ stripe_id: string | null; // TODO: not present in API specification!
91
+ stripe_ref: unknown | null; // TODO: not present in API specification!
92
+ pm_type: unknown | null; // TODO: not present in API specification!
93
+ pm_last_four: unknown | null; // TODO: not present in API specification!
94
+ trial_ends_at: string | null; // TODO: not present in API specification!
95
+ settings: string | null; // TODO: not present in API specification!
96
+ intercom_identity_token?: string; // [resources endpoint only] Helpdesk token
97
+ has_password?: boolean; // [resources endpoint only] SSO or not (enables an ability to change the email)
98
+ permissions: ApiPermission[]; // TODO: not present in API specification!
99
+ roles: ApiRole[]; // TODO: not present in API specification!
100
+ } & ApiCommonData;
101
+ } & Omit<ApiSuccess, 'data'> | ApiError;
102
+ /* eslint-enable @typescript-eslint/no-redundant-type-constituents */
103
+ export type ApiUserData = Flatten<Exclude<ApiUser, ApiError>['data']>;
104
+
105
+ export type JobFolder = {
106
+ id: number;
107
+ jobsCount: number;
108
+ name: string;
109
+ userId: number;
110
+ };
111
+
112
+ export type ApiJobFolder = {
113
+ data: {
114
+ id: number;
115
+ jobsCount: number;
116
+ name: string;
117
+ userId: number;
118
+ } & ApiCommonData;
119
+ } & Omit<ApiSuccess, 'data'> | ApiError;
120
+
121
+ export type ApiJobFolderData = Flatten<Exclude<ApiJobFolder, ApiError>['data']>;
122
+
123
+ export const userRevivers: Revivers<ApiUser, User> = {
124
+ organisation_id: undefined,
125
+ hide_messages: undefined,
126
+ phone: undefined,
127
+ profession: undefined,
128
+ country: undefined,
129
+ city: undefined,
130
+ address: undefined,
131
+ tips: undefined,
132
+ tags: undefined,
133
+ newsletter_consent: undefined,
134
+ registration_complete: undefined,
135
+ notifications_checked_at: undefined,
136
+ referral: undefined,
137
+ delete_requested: undefined,
138
+ delete_request_notified: undefined,
139
+ stripe_ref: undefined,
140
+ pm_type: undefined,
141
+ pm_last_four: undefined,
142
+ trial_ends_at: undefined,
143
+ settings: undefined,
144
+ permissions: undefined,
145
+ roles: undefined,
146
+
147
+ trialExpiresAt: (data: ApiUserData) => data.trial_expires_at ?? undefined,
148
+ stripeId: (data: ApiUserData) => data.stripe_id ?? undefined,
149
+ };
150
+
151
+ type UpdateUserParams = {
152
+ whatsNewBadge?: boolean;
153
+ videoNotifications?: boolean;
154
+ autosave?: boolean;
155
+ interfaceLanguage?: string;
156
+ languageCode?: string;
157
+ unit?: UnitType;
158
+ password?: string;
159
+ email?: string;
160
+ };
161
+
162
+ export async function getUser(): Promise<User> {
163
+ const path = `/v1/users/${myUser}`;
164
+ const options = { revivers: userRevivers };
165
+
166
+ return request<ApiUser, User>(path, null, null, options);
167
+ }
168
+
169
+ export async function updateUser(
170
+ userId: number | typeof myUser,
171
+ fields: RequireAtLeastOne<UpdateUserParams>,
172
+ ): Promise<Record<string, never>> {
173
+ const path = `/v1/users/${userId}`;
174
+ const body = toApiType(fields);
175
+
176
+ return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
177
+ }
178
+
179
+ export async function deleteUser(userId: number | typeof myUser): Promise<Record<string, never>> {
180
+ const path = `/v1/users/${userId}`;
181
+
182
+ return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
183
+ }
184
+
185
+ export async function listUserFontFamilies(): Promise<FontFamily[]> {
186
+ const pathname = `/v1/users/${myUser}/font-families`;
187
+ const query = getSearchParams({ sort: 'order' });
188
+ const path = `${pathname}?${query}`;
189
+ const options = { revivers: fontFamilyRevivers };
190
+
191
+ type ApiFontFamilyArray = {
192
+ data: ApiFontFamilyData[];
193
+ } & Omit<ApiSuccess, 'data'> | ApiError;
194
+
195
+ return request<ApiFontFamilyArray, FontFamily>(path, null, defaultListHeader, options);
196
+ }
197
+
198
+ export async function listUserHatchingSvgs(): Promise<Svg[]> {
199
+ const pathname = `/v1/users/${myUser}/hatching-svgs`;
200
+ const query = getSearchParams({ sort: 'order' });
201
+ const path = `${pathname}?${query}`;
202
+ const options = { revivers: svgRevivers };
203
+
204
+ type ApiSvgArray = {
205
+ data: ApiSvgData[];
206
+ } & Omit<ApiSuccess, 'data'> | ApiError;
207
+
208
+ return request<ApiSvgArray, Svg>(path, null, defaultListHeader, options);
209
+ }
210
+
211
+ export async function listUserJobs(
212
+ userId: number | typeof myUser,
213
+ title: string,
214
+ page: number,
215
+ options?: Record<string, unknown>
216
+ ): Promise<JobSearchResult> {
217
+ return listJobs(`/v1/users/${userId}/jobs`, title, page, options);
218
+ }
219
+
220
+ export async function listUserFolders(): Promise<JobFolder[]> {
221
+ const path = `/v1/users/${myUser}/folders`;
222
+
223
+ type ApiJobFolderArray = {
224
+ data: ApiJobFolderData[];
225
+ } & Omit<ApiSuccess, 'data'> | ApiError;
226
+
227
+ return request<ApiJobFolderArray, JobFolder>(path);
228
+ }
229
+
230
+ export async function createUserFolder(name: string): Promise<JobFolder> {
231
+ const path = `/v1/users/${myUser}/folders`;
232
+ const body = { name };
233
+
234
+ return request<ApiCommon, JobFolder>(path, body);
235
+ }
236
+
237
+ export async function deleteUserFolder(folderId: number): Promise<Record<string, never>> {
238
+ const path = `/v1/users/${myUser}/folders/${folderId}`;
239
+
240
+ return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
241
+ }
242
+
243
+ export async function renameUserFolder(folderId: number, name: string): Promise<Record<string, never>> {
244
+ const path = `/v1/users/${myUser}/folders/${folderId}`;
245
+ const body = { name };
246
+
247
+ return request<ApiCommon, Record<string, never>>(path, body, null, { method: 'PATCH' });
248
+ }
249
+
250
+ export async function listUserLayers(): Promise<Layer[]> {
251
+ const pathname = `/v1/users/${myUser}/layers`;
252
+ const query = getSearchParams({
253
+ search: {
254
+ pangaea_ready: '1',
255
+ },
256
+ sort: 'order',
257
+ });
258
+ const path = `${pathname}?${query}`;
259
+ const options = { revivers: layerRevivers };
260
+
261
+ type ApiLayerArray = {
262
+ data: ApiLayerData[];
263
+ } & Omit<ApiSuccess, 'data'> | ApiError;
264
+
265
+ return request<ApiLayerArray, Layer>(path, null, defaultListHeader, options);
266
+ }
267
+
268
+ export async function listUserSvgSets(): Promise<SvgSet[]> {
269
+ const pathname = `/v1/users/${myUser}/svg-sets`;
270
+ const query = getSearchParams({
271
+ search: {
272
+ supports_mapcreator: '1',
273
+ type: '!:sprite',
274
+ },
275
+ sort: 'order',
276
+ });
277
+ const path = `${pathname}?${query}`;
278
+ const options = { revivers: svgSetRevivers };
279
+
280
+ type ApiSvgSetArray = {
281
+ data: ApiSvgSetData[];
282
+ } & Omit<ApiSuccess, 'data'> | ApiError;
283
+
284
+ return request<ApiSvgSetArray, SvgSet>(path, null, defaultListHeader, options);
285
+ }
286
+
287
+ export async function findJobShares(jobId: number): Promise<JobShare[]> {
288
+ const pathname = `/v1/users/${myUser}/job-shares`;
289
+ const query = getSearchParams({ search: { job_id: jobId } });
290
+ const path = `${pathname}?${query}`;
291
+
292
+ return request<ApiJobShareArray, JobShare>(path);
293
+ }
294
+
295
+ export async function createUserTrial(
296
+ userId: number | typeof myUser,
297
+ data: Record<string, unknown>,
298
+ ): Promise<Record<string, never>> {
299
+ const pathname = `/v1/users/${userId}/trial`;
300
+ const path = `${pathname}?${deletedNoneParam}`;
301
+ const body = toApiType(data);
302
+
303
+ return request<ApiCommon, Record<string, never>>(path, body);
304
+ }
305
+
306
+ export async function sendUserConfirmationEmail(userId: number | typeof myUser): Promise<Record<string, never>> {
307
+ const path = `/v1/users/${userId}/confirm`;
308
+
309
+ return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'POST' });
310
+ }
311
+
312
+ type BillingPortal = {
313
+ billingPortalUrl: string;
314
+ };
315
+ type ApiBillingPortal = {
316
+ data: {
317
+ billing_portal_url: string;
318
+ };
319
+ } & Omit<ApiSuccess, 'data'> | ApiError;
320
+
321
+ export async function getUserBillingPortalUrl(userId: number | typeof myUser): Promise<string> {
322
+ const path = `/v1/users/${userId}/billing-portal-url`;
323
+
324
+ return request<ApiBillingPortal, BillingPortal>(path).then(
325
+ ({ billingPortalUrl }) => billingPortalUrl,
326
+ );
327
+ }