UNPKG

18 kBJavaScriptView Raw
1// @flow
2/* eslint-disable import/first */
3// PROFILE - API MODULE
4// ============================================================================
5
6/*
7 * WARNING: This file was automatically generated. Do not modify it directly, or
8 * your changes will be overwritten.
9 */
10
11import type { RequestStatus, SwaggerFetchPathOptions } from '../../../utility/Fetch';
12import { SwaggerFetch } from '../../../utility/Fetch';
13import t from 'flow-runtime';
14
15import type {
16 TrovCommonModelProfileProfile,
17 UnexpectedErrorException,
18 TrovCommonModelProfileCustomerProfile,
19 CustomerAddressNotSupportedException,
20 CustomerAgeNotSupportedException,
21 CustomerProfileInformationMissingException,
22 StateOfResidenceNotSupportedException,
23 ArgumentException,
24 UnsupportedImageException,
25 DocumentAccessException,
26} from '../../types_gen/V4';
27import Validators from '../../validators_gen/V4';
28
29/**
30 * Gets the profile for the current user.
31 * @param {Object} header
32 * @param {string} header.Trov-Tenant - The tenant to use for the requests.
33 * @param {string} header.Trov-Market - The market to use for the requests.
34 * @param {string} header.Trov-Client - The identifier of the client making
35 * the request.
36 * @param {string} header.Accept-Language - The language to use for
37 * localization of responses (where applicable).
38 * @param {string} header.Authorization - The bearer access token to authorize
39 * the request (e.g. `bearer TOKEN`)
40 */
41export type getApiProfileHeader = {|
42 'Trov-Tenant': string,
43 'Trov-Market': string,
44 'Trov-Client': string,
45 'Accept-Language': string,
46 Authorization: string
47|};
48
49export type GetApiProfileResponseBody = TrovCommonModelProfileProfile | UnexpectedErrorException;
50
51export type GetApiProfileInit = {
52 header: getApiProfileHeader,
53} & RequestOptions;
54
55export type GetApiProfileOptions = SwaggerFetchPathOptions;
56
57export class GetApiProfile extends SwaggerFetch {
58 constructor(init: GetApiProfileInit, options: GetApiProfileOptions) {
59 const finalInit = {
60 ...init,
61 method: 'GET',
62 };
63 super(finalInit, options);
64
65 this.endpoint = '/api/v4.0/profile';
66 }
67
68 handleResponseStatus(response: Response, parsedBody: GetApiProfileResponseBody): ({
69 response: Response,
70 body: ?GetApiProfileResponseBody,
71 status: RequestStatus,
72 }) {
73 const body = (parsedBody && typeof parsedBody === 'object') ? parsedBody : null;
74 let status = 'MISTAKE';
75
76 switch (response.status) {
77 // 2XX STATUSES
78 case 200:
79 status = 'SUCCESS';
80 // OK
81 if (process.env.DEV_TOOLS) {
82 const TrovCommonModelProfileProfileValidation = Validators.TrovCommonModelProfileProfile.validate(parsedBody);
83 if (TrovCommonModelProfileProfileValidation.hasErrors()) {
84 console.error(JSON.stringify(t.makeJSONError(TrovCommonModelProfileProfileValidation), null, 2));
85 }
86 }
87 break;
88
89 // 5XX STATUSES
90 case 500:
91 status = 'FAILURE';
92 // An unexpected error has occurred.
93 if (process.env.DEV_TOOLS) {
94 const UnexpectedErrorExceptionValidation = Validators.UnexpectedErrorException.validate(parsedBody);
95 if (UnexpectedErrorExceptionValidation.hasErrors()) {
96 console.error(JSON.stringify(t.makeJSONError(UnexpectedErrorExceptionValidation), null, 2));
97 }
98 }
99 break;
100
101
102 default:
103 return super.handleResponseStatus(response, parsedBody, true);
104 }
105
106 return { response, body, status };
107 }
108}
109
110/**
111 * Updates the profile customer for the current user.
112 * @param {unknown} body - The updated info about the profile customer to edit.
113 * @param {Object} header
114 * @param {string} header.Trov-Tenant - The tenant to use for the requests.
115 * @param {string} header.Trov-Market - The market to use for the requests.
116 * @param {string} header.Trov-Client - The identifier of the client making
117 * the request.
118 * @param {string} header.Accept-Language - The language to use for
119 * localization of responses (where applicable).
120 * @param {string} header.Authorization - The bearer access token to authorize
121 * the request (e.g. `bearer TOKEN`)
122 */
123export type putApiProfileCustomerBody = TrovCommonModelProfileCustomerProfile;
124
125export type putApiProfileCustomerHeader = {|
126 'Trov-Tenant': string,
127 'Trov-Market': string,
128 'Trov-Client': string,
129 'Accept-Language': string,
130 Authorization: string
131|};
132
133export type PutApiProfileCustomerResponseBody =
134 | TrovCommonModelProfileProfile
135 | CustomerAddressNotSupportedException
136 | CustomerAgeNotSupportedException
137 | CustomerProfileInformationMissingException
138 | StateOfResidenceNotSupportedException
139 | UnexpectedErrorException;
140
141export type PutApiProfileCustomerInit = {
142 header: putApiProfileCustomerHeader,
143} & RequestOptions;
144
145export type PutApiProfileCustomerOptions = {
146 body: putApiProfileCustomerBody,
147} & SwaggerFetchPathOptions;
148
149export class PutApiProfileCustomer extends SwaggerFetch {
150 constructor(init: PutApiProfileCustomerInit, options: PutApiProfileCustomerOptions) {
151 const finalInit = {
152 ...init,
153 method: 'PUT',
154 body: typeof options.body === 'string' ? options.body : JSON.stringify(options.body),
155 };
156 super(finalInit, options);
157
158 this.endpoint = '/api/v4.0/profile/customer';
159 }
160
161 handleResponseStatus(response: Response, parsedBody: PutApiProfileCustomerResponseBody): ({
162 response: Response,
163 body: ?PutApiProfileCustomerResponseBody,
164 status: RequestStatus,
165 }) {
166 const body = (parsedBody && typeof parsedBody === 'object') ? parsedBody : null;
167 let status = 'MISTAKE';
168
169 switch (response.status) {
170 // 2XX STATUSES
171 case 200:
172 status = 'SUCCESS';
173 // OK
174 if (process.env.DEV_TOOLS) {
175 const TrovCommonModelProfileProfileValidation = Validators.TrovCommonModelProfileProfile.validate(parsedBody);
176 if (TrovCommonModelProfileProfileValidation.hasErrors()) {
177 console.error(JSON.stringify(t.makeJSONError(TrovCommonModelProfileProfileValidation), null, 2));
178 }
179 }
180 break;
181
182 // 4XX STATUSES
183 case 400:
184 status = 'FAILURE';
185
186 if (process.env.DEV_TOOLS && parsedBody && typeof parsedBody === 'object' && parsedBody.ExceptionType) {
187 switch (parsedBody.ExceptionType) {
188 case 'CustomerAddressNotSupportedException':
189 // The customer address is valid, but the address is not
190 // supported.
191 if (process.env.DEV_TOOLS) {
192 Validators.CustomerAddressNotSupportedException.assert(parsedBody);
193 }
194 break;
195
196 case 'CustomerAgeNotSupportedException':
197 // The customer has an age that is not supported.
198 if (process.env.DEV_TOOLS) {
199 Validators.CustomerAgeNotSupportedException.assert(parsedBody);
200 }
201 break;
202
203 case 'CustomerProfileInformationMissingException':
204 // The customer profile is missing information.
205 if (process.env.DEV_TOOLS) {
206 Validators.CustomerProfileInformationMissingException.assert(parsedBody);
207 }
208 break;
209
210 default:
211 console.warn(`${this.constructor.name} has no case for a "${response.status}" status and a differentiating key "ExceptionType" of ${JSON.stringify(parsedBody.ExceptionType)}.`);
212 break;
213 }
214 }
215
216 break;
217
218 // 5XX STATUSES
219 case 500:
220 status = 'FAILURE';
221
222 if (process.env.DEV_TOOLS && parsedBody && typeof parsedBody === 'object' && parsedBody.ExceptionType) {
223 switch (parsedBody.ExceptionType) {
224 case 'StateOfResidenceNotSupportedException':
225 // Customer does not reside in an active US state.
226 if (process.env.DEV_TOOLS) {
227 Validators.StateOfResidenceNotSupportedException.assert(parsedBody);
228 }
229 break;
230
231 case 'UnexpectedErrorException':
232 // An unexpected error has occurred.
233 if (process.env.DEV_TOOLS) {
234 Validators.UnexpectedErrorException.assert(parsedBody);
235 }
236 break;
237
238 default:
239 console.warn(`${this.constructor.name} has no case for a "${response.status}" status and a differentiating key "ExceptionType" of ${JSON.stringify(parsedBody.ExceptionType)}.`);
240 break;
241 }
242 }
243
244 break;
245
246
247 default:
248 return super.handleResponseStatus(response, parsedBody, true);
249 }
250
251 return { response, body, status };
252 }
253}
254
255/**
256 * Updates the current user's profile photo. The endpoint requires a
257 * MimeMultipart request body, with a single part:- Must contain a single byte
258 * array (binary blob) of the images data.- The 'Content-Type' header set to
259 * the corresponding type of the blob (e.g. a jpg photo may have it set as
260 * 'image/jpeg');
261 * @param {Object} header
262 * @param {string} header.Trov-Tenant - The tenant to use for the requests.
263 * @param {string} header.Trov-Market - The market to use for the requests.
264 * @param {string} header.Trov-Client - The identifier of the client making
265 * the request.
266 * @param {string} header.Accept-Language - The language to use for
267 * localization of responses (where applicable).
268 * @param {string} header.Authorization - The bearer access token to authorize
269 * the request (e.g. `bearer TOKEN`)
270 */
271export type postApiProfilePhotosProfileHeader = {|
272 'Trov-Tenant': string,
273 'Trov-Market': string,
274 'Trov-Client': string,
275 'Accept-Language': string,
276 Authorization: string
277|};
278
279export type PostApiProfilePhotosProfileResponseBody =
280 | TrovCommonModelProfileProfile
281 | ArgumentException
282 | UnsupportedImageException
283 | DocumentAccessException
284 | UnexpectedErrorException;
285
286export type PostApiProfilePhotosProfileInit = {
287 header: postApiProfilePhotosProfileHeader,
288} & RequestOptions;
289
290export type PostApiProfilePhotosProfileOptions = SwaggerFetchPathOptions;
291
292export class PostApiProfilePhotosProfile extends SwaggerFetch {
293 constructor(init: PostApiProfilePhotosProfileInit, options: PostApiProfilePhotosProfileOptions) {
294 const finalInit = {
295 ...init,
296 method: 'POST',
297 };
298 super(finalInit, options);
299
300 this.endpoint = '/api/v4.0/profile/photos/profile';
301 }
302
303 handleResponseStatus(response: Response, parsedBody: PostApiProfilePhotosProfileResponseBody): ({
304 response: Response,
305 body: ?PostApiProfilePhotosProfileResponseBody,
306 status: RequestStatus,
307 }) {
308 const body = (parsedBody && typeof parsedBody === 'object') ? parsedBody : null;
309 let status = 'MISTAKE';
310
311 switch (response.status) {
312 // 2XX STATUSES
313 case 200:
314 status = 'SUCCESS';
315 // OK
316 if (process.env.DEV_TOOLS) {
317 const TrovCommonModelProfileProfileValidation = Validators.TrovCommonModelProfileProfile.validate(parsedBody);
318 if (TrovCommonModelProfileProfileValidation.hasErrors()) {
319 console.error(JSON.stringify(t.makeJSONError(TrovCommonModelProfileProfileValidation), null, 2));
320 }
321 }
322 break;
323
324 // 4XX STATUSES
325 case 400:
326 status = 'FAILURE';
327
328 if (process.env.DEV_TOOLS && parsedBody && typeof parsedBody === 'object' && parsedBody.ExceptionType) {
329 switch (parsedBody.ExceptionType) {
330 case 'ArgumentException':
331 // The user id is an invalid format.
332 if (process.env.DEV_TOOLS) {
333 Validators.ArgumentException.assert(parsedBody);
334 }
335 break;
336
337 case 'UnsupportedImageException':
338 // The file was not a supported image.
339 if (process.env.DEV_TOOLS) {
340 Validators.UnsupportedImageException.assert(parsedBody);
341 }
342 break;
343
344 default:
345 console.warn(`${this.constructor.name} has no case for a "${response.status}" status and a differentiating key "ExceptionType" of ${JSON.stringify(parsedBody.ExceptionType)}.`);
346 break;
347 }
348 }
349
350 break;
351
352 case 404:
353 status = 'FAILURE';
354 // The user does not have access to update the profile photo. The
355 // customer does not exist.
356 if (process.env.DEV_TOOLS) {
357 const DocumentAccessExceptionValidation = Validators.DocumentAccessException.validate(parsedBody);
358 if (DocumentAccessExceptionValidation.hasErrors()) {
359 console.error(JSON.stringify(t.makeJSONError(DocumentAccessExceptionValidation), null, 2));
360 }
361 }
362 break;
363
364 // 5XX STATUSES
365 case 500:
366 status = 'FAILURE';
367 // An unexpected error has occurred.
368 if (process.env.DEV_TOOLS) {
369 const UnexpectedErrorExceptionValidation = Validators.UnexpectedErrorException.validate(parsedBody);
370 if (UnexpectedErrorExceptionValidation.hasErrors()) {
371 console.error(JSON.stringify(t.makeJSONError(UnexpectedErrorExceptionValidation), null, 2));
372 }
373 }
374 break;
375
376
377 default:
378 return super.handleResponseStatus(response, parsedBody, true);
379 }
380
381 return { response, body, status };
382 }
383}
384
385/**
386 * Updates the current user's background photo. The endpoint requires a
387 * MimeMultipart request body, with a single part:- Must contain a single byte
388 * array (binary blob) of the images data.- The 'Content-Type' header set to
389 * the corresponding type of the blob (e.g. a jpg photo may have it set as
390 * 'image/jpeg');
391 * @param {Object} header
392 * @param {string} header.Trov-Tenant - The tenant to use for the requests.
393 * @param {string} header.Trov-Market - The market to use for the requests.
394 * @param {string} header.Trov-Client - The identifier of the client making
395 * the request.
396 * @param {string} header.Accept-Language - The language to use for
397 * localization of responses (where applicable).
398 * @param {string} header.Authorization - The bearer access token to authorize
399 * the request (e.g. `bearer TOKEN`)
400 */
401export type postApiProfilePhotosBackgroundHeader = {|
402 'Trov-Tenant': string,
403 'Trov-Market': string,
404 'Trov-Client': string,
405 'Accept-Language': string,
406 Authorization: string
407|};
408
409export type PostApiProfilePhotosBackgroundResponseBody =
410 | TrovCommonModelProfileProfile
411 | ArgumentException
412 | UnsupportedImageException
413 | DocumentAccessException
414 | UnexpectedErrorException;
415
416export type PostApiProfilePhotosBackgroundInit = {
417 header: postApiProfilePhotosBackgroundHeader,
418} & RequestOptions;
419
420export type PostApiProfilePhotosBackgroundOptions = SwaggerFetchPathOptions;
421
422export class PostApiProfilePhotosBackground extends SwaggerFetch {
423 constructor(init: PostApiProfilePhotosBackgroundInit, options: PostApiProfilePhotosBackgroundOptions) {
424 const finalInit = {
425 ...init,
426 method: 'POST',
427 };
428 super(finalInit, options);
429
430 this.endpoint = '/api/v4.0/profile/photos/background';
431 }
432
433 handleResponseStatus(response: Response, parsedBody: PostApiProfilePhotosBackgroundResponseBody): ({
434 response: Response,
435 body: ?PostApiProfilePhotosBackgroundResponseBody,
436 status: RequestStatus,
437 }) {
438 const body = (parsedBody && typeof parsedBody === 'object') ? parsedBody : null;
439 let status = 'MISTAKE';
440
441 switch (response.status) {
442 // 2XX STATUSES
443 case 200:
444 status = 'SUCCESS';
445 // OK
446 if (process.env.DEV_TOOLS) {
447 const TrovCommonModelProfileProfileValidation = Validators.TrovCommonModelProfileProfile.validate(parsedBody);
448 if (TrovCommonModelProfileProfileValidation.hasErrors()) {
449 console.error(JSON.stringify(t.makeJSONError(TrovCommonModelProfileProfileValidation), null, 2));
450 }
451 }
452 break;
453
454 // 4XX STATUSES
455 case 400:
456 status = 'FAILURE';
457
458 if (process.env.DEV_TOOLS && parsedBody && typeof parsedBody === 'object' && parsedBody.ExceptionType) {
459 switch (parsedBody.ExceptionType) {
460 case 'ArgumentException':
461 // The user id is an invalid format.
462 if (process.env.DEV_TOOLS) {
463 Validators.ArgumentException.assert(parsedBody);
464 }
465 break;
466
467 case 'UnsupportedImageException':
468 // The file was not a supported image.
469 if (process.env.DEV_TOOLS) {
470 Validators.UnsupportedImageException.assert(parsedBody);
471 }
472 break;
473
474 default:
475 console.warn(`${this.constructor.name} has no case for a "${response.status}" status and a differentiating key "ExceptionType" of ${JSON.stringify(parsedBody.ExceptionType)}.`);
476 break;
477 }
478 }
479
480 break;
481
482 case 404:
483 status = 'FAILURE';
484 // The user does not have access to update the background photo. The
485 // customer does not exist.
486 if (process.env.DEV_TOOLS) {
487 const DocumentAccessExceptionValidation = Validators.DocumentAccessException.validate(parsedBody);
488 if (DocumentAccessExceptionValidation.hasErrors()) {
489 console.error(JSON.stringify(t.makeJSONError(DocumentAccessExceptionValidation), null, 2));
490 }
491 }
492 break;
493
494 // 5XX STATUSES
495 case 500:
496 status = 'FAILURE';
497 // An unexpected error has occurred.
498 if (process.env.DEV_TOOLS) {
499 const UnexpectedErrorExceptionValidation = Validators.UnexpectedErrorException.validate(parsedBody);
500 if (UnexpectedErrorExceptionValidation.hasErrors()) {
501 console.error(JSON.stringify(t.makeJSONError(UnexpectedErrorExceptionValidation), null, 2));
502 }
503 }
504 break;
505
506
507 default:
508 return super.handleResponseStatus(response, parsedBody, true);
509 }
510
511 return { response, body, status };
512 }
513}
514