@@ -384,6 +384,181 @@ class Users {
384384 }
385385 } ) ;
386386 }
387+ /**
388+ * Get a user's notification preferences.
389+ * @throws {@link TrophyApi.UnauthorizedError }
390+ * @throws {@link TrophyApi.NotFoundError }
391+ * @throws {@link TrophyApi.UnprocessableEntityError }
392+ *
393+ * @example
394+ * await trophyApi.users.getPreferences("user-123")
395+ */
396+ getPreferences ( id , requestOptions ) {
397+ var _a ;
398+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
399+ const _response = yield core . fetcher ( {
400+ url : ( 0 , url_join_1 . default ) ( ( ( _a = ( yield core . Supplier . get ( this . _options . environment ) ) ) !== null && _a !== void 0 ? _a : environments . TrophyApiEnvironment . Production )
401+ . api , `users/${ id } /preferences` ) ,
402+ method : "GET" ,
403+ headers : {
404+ "X-API-KEY" : yield core . Supplier . get ( this . _options . apiKey ) ,
405+ "X-Fern-Language" : "JavaScript" ,
406+ } ,
407+ contentType : "application/json" ,
408+ timeoutMs : ( requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions . timeoutInSeconds ) != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
409+ maxRetries : requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions . maxRetries ,
410+ } ) ;
411+ if ( _response . ok ) {
412+ return yield serializers . UserPreferencesResponse . parseOrThrow ( _response . body , {
413+ unrecognizedObjectKeys : "passthrough" ,
414+ allowUnrecognizedUnionMembers : true ,
415+ allowUnrecognizedEnumValues : true ,
416+ breadcrumbsPrefix : [ "response" ] ,
417+ } ) ;
418+ }
419+ if ( _response . error . reason === "status-code" ) {
420+ switch ( _response . error . statusCode ) {
421+ case 401 :
422+ throw new TrophyApi . UnauthorizedError ( yield serializers . ErrorBody . parseOrThrow ( _response . error . body , {
423+ unrecognizedObjectKeys : "passthrough" ,
424+ allowUnrecognizedUnionMembers : true ,
425+ allowUnrecognizedEnumValues : true ,
426+ breadcrumbsPrefix : [ "response" ] ,
427+ } ) ) ;
428+ case 404 :
429+ throw new TrophyApi . NotFoundError ( yield serializers . ErrorBody . parseOrThrow ( _response . error . body , {
430+ unrecognizedObjectKeys : "passthrough" ,
431+ allowUnrecognizedUnionMembers : true ,
432+ allowUnrecognizedEnumValues : true ,
433+ breadcrumbsPrefix : [ "response" ] ,
434+ } ) ) ;
435+ case 422 :
436+ throw new TrophyApi . UnprocessableEntityError ( yield serializers . ErrorBody . parseOrThrow ( _response . error . body , {
437+ unrecognizedObjectKeys : "passthrough" ,
438+ allowUnrecognizedUnionMembers : true ,
439+ allowUnrecognizedEnumValues : true ,
440+ breadcrumbsPrefix : [ "response" ] ,
441+ } ) ) ;
442+ default :
443+ throw new errors . TrophyApiError ( {
444+ statusCode : _response . error . statusCode ,
445+ body : _response . error . body ,
446+ } ) ;
447+ }
448+ }
449+ switch ( _response . error . reason ) {
450+ case "non-json" :
451+ throw new errors . TrophyApiError ( {
452+ statusCode : _response . error . statusCode ,
453+ body : _response . error . rawBody ,
454+ } ) ;
455+ case "timeout" :
456+ throw new errors . TrophyApiTimeoutError ( ) ;
457+ case "unknown" :
458+ throw new errors . TrophyApiError ( {
459+ message : _response . error . errorMessage ,
460+ } ) ;
461+ }
462+ } ) ;
463+ }
464+ /**
465+ * Update a user's notification preferences.
466+ * @throws {@link TrophyApi.UnauthorizedError }
467+ * @throws {@link TrophyApi.NotFoundError }
468+ * @throws {@link TrophyApi.UnprocessableEntityError }
469+ *
470+ * @example
471+ * await trophyApi.users.updatePreferences("user-123", {
472+ * notifications: {
473+ * streakReminder: [TrophyApi.NotificationChannel.Email]
474+ * }
475+ * })
476+ *
477+ * @example
478+ * await trophyApi.users.updatePreferences("user-123", {
479+ * notifications: {
480+ * recap: [TrophyApi.NotificationChannel.Email]
481+ * }
482+ * })
483+ *
484+ * @example
485+ * await trophyApi.users.updatePreferences("user-123", {
486+ * notifications: {
487+ * achievementCompleted: [TrophyApi.NotificationChannel.Email, TrophyApi.NotificationChannel.Push]
488+ * }
489+ * })
490+ */
491+ updatePreferences ( id , request = { } , requestOptions ) {
492+ var _a ;
493+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
494+ const _response = yield core . fetcher ( {
495+ url : ( 0 , url_join_1 . default ) ( ( ( _a = ( yield core . Supplier . get ( this . _options . environment ) ) ) !== null && _a !== void 0 ? _a : environments . TrophyApiEnvironment . Production )
496+ . api , `users/${ id } /preferences` ) ,
497+ method : "PATCH" ,
498+ headers : {
499+ "X-API-KEY" : yield core . Supplier . get ( this . _options . apiKey ) ,
500+ "X-Fern-Language" : "JavaScript" ,
501+ } ,
502+ contentType : "application/json" ,
503+ body : yield serializers . UpdateUserPreferencesRequest . jsonOrThrow ( request , {
504+ unrecognizedObjectKeys : "strip" ,
505+ } ) ,
506+ timeoutMs : ( requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions . timeoutInSeconds ) != null ? requestOptions . timeoutInSeconds * 1000 : 60000 ,
507+ maxRetries : requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions . maxRetries ,
508+ } ) ;
509+ if ( _response . ok ) {
510+ return yield serializers . UserPreferencesResponse . parseOrThrow ( _response . body , {
511+ unrecognizedObjectKeys : "passthrough" ,
512+ allowUnrecognizedUnionMembers : true ,
513+ allowUnrecognizedEnumValues : true ,
514+ breadcrumbsPrefix : [ "response" ] ,
515+ } ) ;
516+ }
517+ if ( _response . error . reason === "status-code" ) {
518+ switch ( _response . error . statusCode ) {
519+ case 401 :
520+ throw new TrophyApi . UnauthorizedError ( yield serializers . ErrorBody . parseOrThrow ( _response . error . body , {
521+ unrecognizedObjectKeys : "passthrough" ,
522+ allowUnrecognizedUnionMembers : true ,
523+ allowUnrecognizedEnumValues : true ,
524+ breadcrumbsPrefix : [ "response" ] ,
525+ } ) ) ;
526+ case 404 :
527+ throw new TrophyApi . NotFoundError ( yield serializers . ErrorBody . parseOrThrow ( _response . error . body , {
528+ unrecognizedObjectKeys : "passthrough" ,
529+ allowUnrecognizedUnionMembers : true ,
530+ allowUnrecognizedEnumValues : true ,
531+ breadcrumbsPrefix : [ "response" ] ,
532+ } ) ) ;
533+ case 422 :
534+ throw new TrophyApi . UnprocessableEntityError ( yield serializers . ErrorBody . parseOrThrow ( _response . error . body , {
535+ unrecognizedObjectKeys : "passthrough" ,
536+ allowUnrecognizedUnionMembers : true ,
537+ allowUnrecognizedEnumValues : true ,
538+ breadcrumbsPrefix : [ "response" ] ,
539+ } ) ) ;
540+ default :
541+ throw new errors . TrophyApiError ( {
542+ statusCode : _response . error . statusCode ,
543+ body : _response . error . body ,
544+ } ) ;
545+ }
546+ }
547+ switch ( _response . error . reason ) {
548+ case "non-json" :
549+ throw new errors . TrophyApiError ( {
550+ statusCode : _response . error . statusCode ,
551+ body : _response . error . rawBody ,
552+ } ) ;
553+ case "timeout" :
554+ throw new errors . TrophyApiTimeoutError ( ) ;
555+ case "unknown" :
556+ throw new errors . TrophyApiError ( {
557+ message : _response . error . errorMessage ,
558+ } ) ;
559+ }
560+ } ) ;
561+ }
387562 /**
388563 * Get a single user's progress against all active metrics.
389564 * @throws {@link TrophyApi.UnauthorizedError }
0 commit comments