Skip to content

Commit

Permalink
Refactor client.ts and interfaces.ts
Browse files Browse the repository at this point in the history
This commit refactors the client.ts and interfaces.ts files. It adds a new function getUserAccountMetadata() to the NotificationAPIClientSDK, which makes a GET request to retrieve user account metadata. Additionally, the UserAccountMetadata interface is added to the interfaces.ts file, defining the structure of the metadata object.
  • Loading branch information
mbasadi committed Oct 22, 2024
1 parent 4d74c0c commit b70b700
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
Channels,
DeliveryOptionsForEmail,
DeliveryOptionsForInappWeb,
PostUserRequest
PostUserRequest,
UserAccountMetadata
} from './interfaces';
import {
GetPreferencesResponse,
Expand Down Expand Up @@ -71,6 +72,7 @@ type NotificationAPIClientSDK = {
}>
): Promise<any>;
postUser(params: PostUserRequest): Promise<any>;
getUserAccountMetadata(): Promise<UserAccountMetadata>;
};
websocket: {
object: WebSocket | undefined;
Expand Down Expand Up @@ -104,6 +106,7 @@ type NotificationAPIClientSDK = {
}): Promise<void>;
getPreferences(): Promise<GetPreferencesResponse>;
identify(params: PostUserRequest): Promise<void>;
getUserAccountMetadata(): Promise<UserAccountMetadata>;
};

export const NotificationAPIClientSDK: NotificationAPIClientSDK = {
Expand Down Expand Up @@ -156,6 +159,9 @@ export const NotificationAPIClientSDK: NotificationAPIClientSDK = {
},
postUser: function (params: PostUserRequest) {
return NotificationAPIClientSDK.rest.generic('POST', '', params);
},
getUserAccountMetadata: function () {
return NotificationAPIClientSDK.rest.generic('GET', 'account_metadata');
}
},
websocket: {
Expand Down Expand Up @@ -293,5 +299,8 @@ export const NotificationAPIClientSDK: NotificationAPIClientSDK = {
);
}
return NotificationAPIClientSDK.rest.postUser(params);
},
getUserAccountMetadata: async () => {
return NotificationAPIClientSDK.rest.getUserAccountMetadata();
}
};
5 changes: 5 additions & 0 deletions lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ export interface PushSubscription {
export interface WebPushToken {
sub: PushSubscription;
}
export interface UserAccountMetadata {
logo: string;
environmentVapidPublicKey: string;
hasWebPushEnabled: boolean;
}

0 comments on commit b70b700

Please sign in to comment.