Skip to content

Commit 80f4b5b

Browse files
Automatically update NodeJS SDK
1 parent adf40fc commit 80f4b5b

34 files changed

Lines changed: 621 additions & 1 deletion

api/resources/users/client/Client.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,44 @@ export declare class Users {
7474
* })
7575
*/
7676
update(id: string, request: TrophyApi.UpdatedUser, requestOptions?: Users.RequestOptions): Promise<TrophyApi.User>;
77+
/**
78+
* Get a user's notification preferences.
79+
* @throws {@link TrophyApi.UnauthorizedError}
80+
* @throws {@link TrophyApi.NotFoundError}
81+
* @throws {@link TrophyApi.UnprocessableEntityError}
82+
*
83+
* @example
84+
* await trophyApi.users.getPreferences("user-123")
85+
*/
86+
getPreferences(id: string, requestOptions?: Users.RequestOptions): Promise<TrophyApi.UserPreferencesResponse>;
87+
/**
88+
* Update a user's notification preferences.
89+
* @throws {@link TrophyApi.UnauthorizedError}
90+
* @throws {@link TrophyApi.NotFoundError}
91+
* @throws {@link TrophyApi.UnprocessableEntityError}
92+
*
93+
* @example
94+
* await trophyApi.users.updatePreferences("user-123", {
95+
* notifications: {
96+
* streakReminder: [TrophyApi.NotificationChannel.Email]
97+
* }
98+
* })
99+
*
100+
* @example
101+
* await trophyApi.users.updatePreferences("user-123", {
102+
* notifications: {
103+
* recap: [TrophyApi.NotificationChannel.Email]
104+
* }
105+
* })
106+
*
107+
* @example
108+
* await trophyApi.users.updatePreferences("user-123", {
109+
* notifications: {
110+
* achievementCompleted: [TrophyApi.NotificationChannel.Email, TrophyApi.NotificationChannel.Push]
111+
* }
112+
* })
113+
*/
114+
updatePreferences(id: string, request?: TrophyApi.UpdateUserPreferencesRequest, requestOptions?: Users.RequestOptions): Promise<TrophyApi.UserPreferencesResponse>;
77115
/**
78116
* Get a single user's progress against all active metrics.
79117
* @throws {@link TrophyApi.UnauthorizedError}

api/resources/users/client/Client.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
import * as TrophyApi from "../../../..";
5+
/**
6+
* @example
7+
* {
8+
* notifications: {
9+
* streakReminder: [TrophyApi.NotificationChannel.Email]
10+
* }
11+
* }
12+
*
13+
* @example
14+
* {
15+
* notifications: {
16+
* recap: [TrophyApi.NotificationChannel.Email]
17+
* }
18+
* }
19+
*
20+
* @example
21+
* {
22+
* notifications: {
23+
* achievementCompleted: [TrophyApi.NotificationChannel.Email, TrophyApi.NotificationChannel.Push]
24+
* }
25+
* }
26+
*/
27+
export interface UpdateUserPreferencesRequest {
28+
notifications?: TrophyApi.NotificationPreferences;
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
/**
3+
* This file was auto-generated by Fern from our API Definition.
4+
*/
5+
Object.defineProperty(exports, "__esModule", { value: true });

api/resources/users/client/requests/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { UpdateUserPreferencesRequest } from "./UpdateUserPreferencesRequest";
12
export { UsersMetricEventSummaryRequest } from "./UsersMetricEventSummaryRequest";
23
export { UsersAchievementsRequest } from "./UsersAchievementsRequest";
34
export { UsersStreakRequest } from "./UsersStreakRequest";

api/types/NotificationChannel.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
/**
5+
* A notification delivery channel.
6+
*/
7+
export declare type NotificationChannel = "email" | "push";
8+
export declare const NotificationChannel: {
9+
readonly Email: "email";
10+
readonly Push: "push";
11+
};

api/types/NotificationChannel.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
/**
3+
* This file was auto-generated by Fern from our API Definition.
4+
*/
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.NotificationChannel = void 0;
7+
exports.NotificationChannel = {
8+
Email: "email",
9+
Push: "push",
10+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
import * as TrophyApi from "..";
5+
/**
6+
* Notification preferences for each notification type.
7+
*/
8+
export interface NotificationPreferences {
9+
/** Channels to receive achievement completion notifications on. */
10+
achievementCompleted?: TrophyApi.NotificationChannel[];
11+
/** Channels to receive recap notifications on. */
12+
recap?: TrophyApi.NotificationChannel[];
13+
/** Channels to receive reactivation notifications on. */
14+
reactivation?: TrophyApi.NotificationChannel[];
15+
/** Channels to receive streak reminder notifications on. */
16+
streakReminder?: TrophyApi.NotificationChannel[];
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
/**
3+
* This file was auto-generated by Fern from our API Definition.
4+
*/
5+
Object.defineProperty(exports, "__esModule", { value: true });

api/types/NotificationType.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
/**
5+
* A type of notification that can be configured.
6+
*/
7+
export declare type NotificationType = "achievement_completed" | "recap" | "reactivation" | "streak_reminder";
8+
export declare const NotificationType: {
9+
readonly AchievementCompleted: "achievement_completed";
10+
readonly Recap: "recap";
11+
readonly Reactivation: "reactivation";
12+
readonly StreakReminder: "streak_reminder";
13+
};

0 commit comments

Comments
 (0)