@canonmsg/backend-contracts 1.1.1 → 1.2.0

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.
@@ -11,6 +11,18 @@ function normalizeStringArray(value) {
11
11
  return [];
12
12
  return value.filter((entry) => typeof entry === 'string');
13
13
  }
14
+ function normalizeReactions(value) {
15
+ if (!isRecord(value))
16
+ return undefined;
17
+ const reactions = {};
18
+ for (const [reaction, userIds] of Object.entries(value)) {
19
+ const normalizedUserIds = normalizeStringArray(userIds);
20
+ if (reaction.length > 0 && normalizedUserIds.length > 0) {
21
+ reactions[reaction] = normalizedUserIds;
22
+ }
23
+ }
24
+ return Object.keys(reactions).length > 0 ? reactions : undefined;
25
+ }
14
26
  function normalizeTimestamp(value) {
15
27
  if (value instanceof Date)
16
28
  return value;
@@ -137,5 +149,9 @@ function serializeStoredMessage(input) {
137
149
  if (runtimeCard) {
138
150
  result.runtimeCard = runtimeCard;
139
151
  }
152
+ const reactions = normalizeReactions(data.reactions);
153
+ if (reactions) {
154
+ result.reactions = reactions;
155
+ }
140
156
  return result;
141
157
  }
package/dist/message.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface ForwardedFrom {
6
6
  sourceConversationId: string;
7
7
  messageId: string;
8
8
  }
9
+ export type SerializedReactions = Record<string, string[]>;
9
10
  export interface SerializedContactCard {
10
11
  userId: string;
11
12
  displayName: string;
@@ -38,6 +39,7 @@ export interface SerializedMessage {
38
39
  contactCard?: SerializedContactCard;
39
40
  /** Durable canon.card.v1 runtime card content, passed through opaquely. */
40
41
  runtimeCard?: Record<string, unknown>;
42
+ reactions?: SerializedReactions;
41
43
  }
42
44
  export interface SerializeMessageInput {
43
45
  id: string;
package/dist/message.js CHANGED
@@ -8,6 +8,18 @@ function normalizeStringArray(value) {
8
8
  return [];
9
9
  return value.filter((entry) => typeof entry === 'string');
10
10
  }
11
+ function normalizeReactions(value) {
12
+ if (!isRecord(value))
13
+ return undefined;
14
+ const reactions = {};
15
+ for (const [reaction, userIds] of Object.entries(value)) {
16
+ const normalizedUserIds = normalizeStringArray(userIds);
17
+ if (reaction.length > 0 && normalizedUserIds.length > 0) {
18
+ reactions[reaction] = normalizedUserIds;
19
+ }
20
+ }
21
+ return Object.keys(reactions).length > 0 ? reactions : undefined;
22
+ }
11
23
  function normalizeTimestamp(value) {
12
24
  if (value instanceof Date)
13
25
  return value;
@@ -134,5 +146,9 @@ export function serializeStoredMessage(input) {
134
146
  if (runtimeCard) {
135
147
  result.runtimeCard = runtimeCard;
136
148
  }
149
+ const reactions = normalizeReactions(data.reactions);
150
+ if (reactions) {
151
+ result.reactions = reactions;
152
+ }
137
153
  return result;
138
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/backend-contracts",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Canon backend contract helpers shared by Functions and stream-service",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",