@misternooblet/squara-types 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { NotificationType,
|
|
2
|
-
export { GroupUpdateNotification, PendingSettlementNotification, NewGroupMemberNotification, NewGroupExpenseNotification } from "./notification";
|
|
1
|
+
export { NotificationType, SquaraNotification, NOTIFICATION_TYPE_TO_PAYLOAD_MAP, NotificationPayload, NotificationDataInput, GroupUpdateNotification, PendingSettlementNotification, NewGroupMemberNotification, NewGroupExpenseNotification, isNotificationType, isGroupUpdate, isPendingSettlement, isNewGroupMember, isNewGroupExpense, parseNotificationData, buildNotificationData, } from './notification';
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NOTIFICATION_TYPE_TO_PAYLOAD_MAP = exports.NotificationType = void 0;
|
|
3
|
+
exports.buildNotificationData = exports.parseNotificationData = exports.isNewGroupExpense = exports.isNewGroupMember = exports.isPendingSettlement = exports.isGroupUpdate = exports.isNotificationType = exports.NOTIFICATION_TYPE_TO_PAYLOAD_MAP = exports.NotificationType = void 0;
|
|
4
4
|
var notification_1 = require("./notification");
|
|
5
5
|
Object.defineProperty(exports, "NotificationType", { enumerable: true, get: function () { return notification_1.NotificationType; } });
|
|
6
6
|
Object.defineProperty(exports, "NOTIFICATION_TYPE_TO_PAYLOAD_MAP", { enumerable: true, get: function () { return notification_1.NOTIFICATION_TYPE_TO_PAYLOAD_MAP; } });
|
|
7
|
+
Object.defineProperty(exports, "isNotificationType", { enumerable: true, get: function () { return notification_1.isNotificationType; } });
|
|
8
|
+
Object.defineProperty(exports, "isGroupUpdate", { enumerable: true, get: function () { return notification_1.isGroupUpdate; } });
|
|
9
|
+
Object.defineProperty(exports, "isPendingSettlement", { enumerable: true, get: function () { return notification_1.isPendingSettlement; } });
|
|
10
|
+
Object.defineProperty(exports, "isNewGroupMember", { enumerable: true, get: function () { return notification_1.isNewGroupMember; } });
|
|
11
|
+
Object.defineProperty(exports, "isNewGroupExpense", { enumerable: true, get: function () { return notification_1.isNewGroupExpense; } });
|
|
12
|
+
Object.defineProperty(exports, "parseNotificationData", { enumerable: true, get: function () { return notification_1.parseNotificationData; } });
|
|
13
|
+
Object.defineProperty(exports, "buildNotificationData", { enumerable: true, get: function () { return notification_1.buildNotificationData; } });
|
|
@@ -4,14 +4,16 @@ export declare enum NotificationType {
|
|
|
4
4
|
NewGroupMember = "NEW_GROUP_MEMBER",
|
|
5
5
|
NewGroupExpense = "NEW_GROUP_EXPENSE"
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
7
|
+
export interface SquaraNotification {
|
|
8
8
|
type: NotificationType;
|
|
9
|
+
title?: string;
|
|
10
|
+
body?: string;
|
|
9
11
|
}
|
|
10
|
-
export interface GroupUpdateNotification extends
|
|
12
|
+
export interface GroupUpdateNotification extends SquaraNotification {
|
|
11
13
|
type: NotificationType.GroupUpdate;
|
|
12
14
|
groupId: string;
|
|
13
15
|
}
|
|
14
|
-
export interface PendingSettlementNotification extends
|
|
16
|
+
export interface PendingSettlementNotification extends SquaraNotification {
|
|
15
17
|
type: NotificationType.PendingSettlement;
|
|
16
18
|
settlementId: string;
|
|
17
19
|
settlementFromUserId: string;
|
|
@@ -20,12 +22,12 @@ export interface PendingSettlementNotification extends Notification {
|
|
|
20
22
|
amount: number;
|
|
21
23
|
currency: string;
|
|
22
24
|
}
|
|
23
|
-
export interface NewGroupMemberNotification extends
|
|
25
|
+
export interface NewGroupMemberNotification extends SquaraNotification {
|
|
24
26
|
type: NotificationType.NewGroupMember;
|
|
25
27
|
groupId: string;
|
|
26
28
|
userId: string;
|
|
27
29
|
}
|
|
28
|
-
export interface NewGroupExpenseNotification extends
|
|
30
|
+
export interface NewGroupExpenseNotification extends SquaraNotification {
|
|
29
31
|
type: NotificationType.NewGroupExpense;
|
|
30
32
|
groupId: string;
|
|
31
33
|
expenseId: string;
|
|
@@ -38,3 +40,12 @@ export declare const NOTIFICATION_TYPE_TO_PAYLOAD_MAP: {
|
|
|
38
40
|
NEW_GROUP_MEMBER: NewGroupMemberNotification;
|
|
39
41
|
NEW_GROUP_EXPENSE: NewGroupExpenseNotification;
|
|
40
42
|
};
|
|
43
|
+
export type NotificationPayload = (typeof NOTIFICATION_TYPE_TO_PAYLOAD_MAP)[keyof typeof NOTIFICATION_TYPE_TO_PAYLOAD_MAP];
|
|
44
|
+
export type NotificationDataInput<T extends NotificationType> = Omit<(typeof NOTIFICATION_TYPE_TO_PAYLOAD_MAP)[T], keyof SquaraNotification>;
|
|
45
|
+
export declare function isNotificationType(value: unknown): value is NotificationType;
|
|
46
|
+
export declare function isGroupUpdate(p: NotificationPayload): p is GroupUpdateNotification;
|
|
47
|
+
export declare function isPendingSettlement(p: NotificationPayload): p is PendingSettlementNotification;
|
|
48
|
+
export declare function isNewGroupMember(p: NotificationPayload): p is NewGroupMemberNotification;
|
|
49
|
+
export declare function isNewGroupExpense(p: NotificationPayload): p is NewGroupExpenseNotification;
|
|
50
|
+
export declare function parseNotificationData(data: Record<string, string>): NotificationPayload | null;
|
|
51
|
+
export declare function buildNotificationData<T extends NotificationType>(type: T, payload: NotificationDataInput<T>): Record<string, string>;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// ─── Enum ─────────────────────────────────────────────────────────────────
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.NOTIFICATION_TYPE_TO_PAYLOAD_MAP = exports.NotificationType = void 0;
|
|
5
|
+
exports.isNotificationType = isNotificationType;
|
|
6
|
+
exports.isGroupUpdate = isGroupUpdate;
|
|
7
|
+
exports.isPendingSettlement = isPendingSettlement;
|
|
8
|
+
exports.isNewGroupMember = isNewGroupMember;
|
|
9
|
+
exports.isNewGroupExpense = isNewGroupExpense;
|
|
10
|
+
exports.parseNotificationData = parseNotificationData;
|
|
11
|
+
exports.buildNotificationData = buildNotificationData;
|
|
4
12
|
var NotificationType;
|
|
5
13
|
(function (NotificationType) {
|
|
6
14
|
NotificationType["GroupUpdate"] = "GROUP_UPDATE";
|
|
@@ -8,9 +16,76 @@ var NotificationType;
|
|
|
8
16
|
NotificationType["NewGroupMember"] = "NEW_GROUP_MEMBER";
|
|
9
17
|
NotificationType["NewGroupExpense"] = "NEW_GROUP_EXPENSE";
|
|
10
18
|
})(NotificationType || (exports.NotificationType = NotificationType = {}));
|
|
19
|
+
// ─── Map ──────────────────────────────────────────────────────────────────
|
|
11
20
|
exports.NOTIFICATION_TYPE_TO_PAYLOAD_MAP = {
|
|
12
21
|
[NotificationType.GroupUpdate]: {},
|
|
13
22
|
[NotificationType.PendingSettlement]: {},
|
|
14
23
|
[NotificationType.NewGroupMember]: {},
|
|
15
24
|
[NotificationType.NewGroupExpense]: {},
|
|
16
25
|
};
|
|
26
|
+
// ─── Type guards ──────────────────────────────────────────────────────────
|
|
27
|
+
function isNotificationType(value) {
|
|
28
|
+
return typeof value === 'string' && Object.values(NotificationType).includes(value);
|
|
29
|
+
}
|
|
30
|
+
function isGroupUpdate(p) {
|
|
31
|
+
return p.type === NotificationType.GroupUpdate;
|
|
32
|
+
}
|
|
33
|
+
function isPendingSettlement(p) {
|
|
34
|
+
return p.type === NotificationType.PendingSettlement;
|
|
35
|
+
}
|
|
36
|
+
function isNewGroupMember(p) {
|
|
37
|
+
return p.type === NotificationType.NewGroupMember;
|
|
38
|
+
}
|
|
39
|
+
function isNewGroupExpense(p) {
|
|
40
|
+
return p.type === NotificationType.NewGroupExpense;
|
|
41
|
+
}
|
|
42
|
+
// ─── Parser (frontend) ────────────────────────────────────────────────────
|
|
43
|
+
// Firebase sends all data values as strings — validates and re-shapes to typed payload
|
|
44
|
+
function parseNotificationData(data) {
|
|
45
|
+
if (!isNotificationType(data.type))
|
|
46
|
+
return null;
|
|
47
|
+
const base = { title: data.title, body: data.body };
|
|
48
|
+
switch (data.type) {
|
|
49
|
+
case NotificationType.GroupUpdate:
|
|
50
|
+
if (!data.groupId)
|
|
51
|
+
return null;
|
|
52
|
+
return { ...base, type: data.type, groupId: data.groupId };
|
|
53
|
+
case NotificationType.PendingSettlement:
|
|
54
|
+
if (!data.settlementId || !data.groupId)
|
|
55
|
+
return null;
|
|
56
|
+
return {
|
|
57
|
+
...base,
|
|
58
|
+
type: data.type,
|
|
59
|
+
settlementId: data.settlementId,
|
|
60
|
+
settlementFromUserId: data.settlementFromUserId,
|
|
61
|
+
settlementToUserId: data.settlementToUserId,
|
|
62
|
+
groupId: data.groupId,
|
|
63
|
+
amount: parseFloat(data.amount),
|
|
64
|
+
currency: data.currency,
|
|
65
|
+
};
|
|
66
|
+
case NotificationType.NewGroupMember:
|
|
67
|
+
if (!data.groupId || !data.userId)
|
|
68
|
+
return null;
|
|
69
|
+
return { ...base, type: data.type, groupId: data.groupId, userId: data.userId };
|
|
70
|
+
case NotificationType.NewGroupExpense:
|
|
71
|
+
if (!data.groupId || !data.expenseId)
|
|
72
|
+
return null;
|
|
73
|
+
return {
|
|
74
|
+
...base,
|
|
75
|
+
type: data.type,
|
|
76
|
+
groupId: data.groupId,
|
|
77
|
+
expenseId: data.expenseId,
|
|
78
|
+
amount: parseFloat(data.amount),
|
|
79
|
+
currency: data.currency,
|
|
80
|
+
};
|
|
81
|
+
default:
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// ─── Builder (backend) ────────────────────────────────────────────────────
|
|
86
|
+
// Pass type + exact required fields → Firebase-ready Record<string, string>
|
|
87
|
+
// IDE errors on missing fields, wrong fields, and wrong value types
|
|
88
|
+
function buildNotificationData(type, payload) {
|
|
89
|
+
const raw = { type, ...payload };
|
|
90
|
+
return Object.fromEntries(Object.entries(raw).map(([k, v]) => [k, String(v)]));
|
|
91
|
+
}
|