splitwise
Version:
A TypeScript SDK for the Splitwise API.
66 lines • 2.46 kB
JavaScript
/**
* Splitwise notification type values.
*
* The API returns notification.type as a small integer. The mapping below was
* derived from the Rust SDK (pbar1/splitwise-rs), which appears to be the
* most thoroughly enumerated reference. Splitwise's official OpenAPI spec
* doesn't enumerate the values.
*
* **Note:** Splitwise may add new notification types without warning. Treat
* `Notification.type` as `number` and use these constants for comparison;
* unknown values should be handled gracefully (e.g. fall through to a default
* branch in a switch).
*/
export const NotificationType = {
ExpenseAdded: 0,
ExpenseUpdated: 1,
ExpenseDeleted: 2,
CommentAdded: 3,
AddedToGroup: 4,
RemovedFromGroup: 5,
GroupDeleted: 6,
GroupSettingsChanged: 7,
AddedAsFriend: 8,
RemovedAsFriend: 9,
News: 10,
DebtSimplification: 11,
GroupUndeleted: 12,
ExpenseUndeleted: 13,
GroupCurrencyConversion: 14,
FriendCurrencyConversion: 15,
};
const NAMES = {
[]: 'expense_added',
[]: 'expense_updated',
[]: 'expense_deleted',
[]: 'comment_added',
[]: 'added_to_group',
[]: 'removed_from_group',
[]: 'group_deleted',
[]: 'group_settings_changed',
[]: 'added_as_friend',
[]: 'removed_as_friend',
[]: 'news',
[]: 'debt_simplification',
[]: 'group_undeleted',
[]: 'expense_undeleted',
[]: 'group_currency_conversion',
[]: 'friend_currency_conversion',
};
/**
* Returns the snake_case name for a notification type id, or `undefined` if
* the id is unknown. Useful for logging and switch-style branching:
*
* @example
* ```ts
* switch (notificationTypeName(notification.type)) {
* case 'expense_added': ...
* case 'comment_added': ...
* default: ... // including unknown future values
* }
* ```
*/
export function notificationTypeName(typeId) {
return NAMES[typeId];
}
//# sourceMappingURL=notification-types.js.map