splitwise
Version:
A TypeScript SDK for the Splitwise API.
70 lines • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationType = void 0;
exports.notificationTypeName = notificationTypeName;
/**
* 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).
*/
exports.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 = {
[exports.NotificationType.ExpenseAdded]: 'expense_added',
[exports.NotificationType.ExpenseUpdated]: 'expense_updated',
[exports.NotificationType.ExpenseDeleted]: 'expense_deleted',
[exports.NotificationType.CommentAdded]: 'comment_added',
[exports.NotificationType.AddedToGroup]: 'added_to_group',
[exports.NotificationType.RemovedFromGroup]: 'removed_from_group',
[exports.NotificationType.GroupDeleted]: 'group_deleted',
[exports.NotificationType.GroupSettingsChanged]: 'group_settings_changed',
[exports.NotificationType.AddedAsFriend]: 'added_as_friend',
[exports.NotificationType.RemovedAsFriend]: 'removed_as_friend',
[exports.NotificationType.News]: 'news',
[exports.NotificationType.DebtSimplification]: 'debt_simplification',
[exports.NotificationType.GroupUndeleted]: 'group_undeleted',
[exports.NotificationType.ExpenseUndeleted]: 'expense_undeleted',
[exports.NotificationType.GroupCurrencyConversion]: 'group_currency_conversion',
[exports.NotificationType.FriendCurrencyConversion]: '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
* }
* ```
*/
function notificationTypeName(typeId) {
return NAMES[typeId];
}
//# sourceMappingURL=notification-types.js.map