@stream-io/feeds-client 0.2.12 → 0.2.14

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/index.js +2 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +22 -14
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +3 -2
  7. package/dist/es/react-bindings.mjs +22 -14
  8. package/dist/es/react-bindings.mjs.map +1 -1
  9. package/dist/{index-o7AeSkxa.js → index-B08vVRSZ.js} +159 -9
  10. package/dist/index-B08vVRSZ.js.map +1 -0
  11. package/dist/{index-D7QtnkUs.mjs → index-B3HHiF9S.mjs} +159 -9
  12. package/dist/index-B3HHiF9S.mjs.map +1 -0
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/dist/types/bindings/react/hooks/feed-state-hooks/useAggregatedActivities.d.ts +9 -4
  15. package/dist/types/bindings/react/hooks/feed-state-hooks/useAggregatedActivities.d.ts.map +1 -1
  16. package/dist/types/bindings/react/hooks/feed-state-hooks/useIsAggregatedActivityRead.d.ts.map +1 -1
  17. package/dist/types/common/real-time/StableWSConnection.d.ts +3 -3
  18. package/dist/types/common/real-time/StableWSConnection.d.ts.map +1 -1
  19. package/dist/types/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.d.ts +24 -0
  20. package/dist/types/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.d.ts.map +1 -0
  21. package/dist/types/feed/event-handlers/aggregated-feed/index.d.ts +2 -0
  22. package/dist/types/feed/event-handlers/aggregated-feed/index.d.ts.map +1 -0
  23. package/dist/types/feed/event-handlers/index.d.ts +1 -1
  24. package/dist/types/feed/event-handlers/index.d.ts.map +1 -1
  25. package/dist/types/feed/feed.d.ts +2 -2
  26. package/dist/types/feed/feed.d.ts.map +1 -1
  27. package/dist/types/feeds-client/feeds-client.d.ts +2 -2
  28. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts.map +1 -1
  29. package/dist/types/gen/models/index.d.ts +17 -1
  30. package/dist/types/gen/models/index.d.ts.map +1 -1
  31. package/dist/types/utils/unique-array-merge.d.ts +1 -0
  32. package/dist/types/utils/unique-array-merge.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/src/bindings/react/hooks/feed-state-hooks/useAggregatedActivities.ts +28 -4
  35. package/src/bindings/react/hooks/feed-state-hooks/useIsAggregatedActivityRead.ts +4 -5
  36. package/src/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.test.ts +644 -0
  37. package/src/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.ts +193 -0
  38. package/src/feed/event-handlers/aggregated-feed/index.ts +1 -0
  39. package/src/feed/event-handlers/index.ts +1 -1
  40. package/src/feed/feed.ts +23 -1
  41. package/src/gen/model-decoders/decoders.ts +14 -0
  42. package/src/gen/model-decoders/event-decoder-mapping.ts +3 -0
  43. package/src/gen/models/index.ts +26 -2
  44. package/src/utils/unique-array-merge.ts +30 -0
  45. package/dist/index-D7QtnkUs.mjs.map +0 -1
  46. package/dist/index-o7AeSkxa.js.map +0 -1
  47. package/dist/types/feed/event-handlers/notification-feed/handle-notification-feed-updated.d.ts +0 -11
  48. package/dist/types/feed/event-handlers/notification-feed/handle-notification-feed-updated.d.ts.map +0 -1
  49. package/dist/types/feed/event-handlers/notification-feed/index.d.ts +0 -2
  50. package/dist/types/feed/event-handlers/notification-feed/index.d.ts.map +0 -1
  51. package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.test.ts +0 -120
  52. package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.ts +0 -54
  53. package/src/feed/event-handlers/notification-feed/index.ts +0 -1
@@ -1,11 +0,0 @@
1
- import type { Feed } from '../../../feed';
2
- import type { AggregatedActivityResponse, NotificationFeedUpdatedEvent, NotificationStatusResponse } from '../../../gen/models';
3
- import type { EventPayload, UpdateStateResult } from '../../../types-internal';
4
- export declare const updateNotificationFeedFromEvent: (event: NotificationFeedUpdatedEvent) => UpdateStateResult<{
5
- data?: {
6
- notification_status?: NotificationStatusResponse;
7
- aggregated_activities?: AggregatedActivityResponse[];
8
- };
9
- }>;
10
- export declare function handleNotificationFeedUpdated(this: Feed, event: EventPayload<'feeds.notification_feed.updated'>): void;
11
- //# sourceMappingURL=handle-notification-feed-updated.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle-notification-feed-updated.d.ts","sourceRoot":"","sources":["../../../../../src/feed/event-handlers/notification-feed/handle-notification-feed-updated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE/E,eAAO,MAAM,+BAA+B,GAC1C,OAAO,4BAA4B,KAClC,iBAAiB,CAAC;IACnB,IAAI,CAAC,EAAE;QACL,mBAAmB,CAAC,EAAE,0BAA0B,CAAC;QACjD,qBAAqB,CAAC,EAAE,0BAA0B,EAAE,CAAC;KACtD,CAAC;CACH,CAyBA,CAAC;AAEF,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,YAAY,CAAC,iCAAiC,CAAC,QASvD"}
@@ -1,2 +0,0 @@
1
- export * from './handle-notification-feed-updated';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/feed/event-handlers/notification-feed/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA"}
@@ -1,120 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type {
3
- NotificationFeedUpdatedEvent,
4
- NotificationStatusResponse,
5
- AggregatedActivityResponse,
6
- } from '../../../gen/models';
7
- import { updateNotificationFeedFromEvent } from './handle-notification-feed-updated';
8
-
9
- const createMockNotificationFeedUpdatedEvent = (
10
- overrides: Partial<NotificationFeedUpdatedEvent> = {},
11
- ): NotificationFeedUpdatedEvent => ({
12
- created_at: new Date(),
13
- fid: 'user:notification',
14
- custom: {},
15
- type: 'feeds.notification_feed.updated',
16
- ...overrides,
17
- });
18
-
19
- const createMockNotificationStatus = (
20
- overrides: Partial<NotificationStatusResponse> = {},
21
- ): NotificationStatusResponse => ({
22
- unread: 0,
23
- unseen: 0,
24
- ...overrides,
25
- });
26
-
27
- const createMockAggregatedActivity = (
28
- overrides: Partial<AggregatedActivityResponse> = {},
29
- ): AggregatedActivityResponse => ({
30
- activity_count: 1,
31
- created_at: new Date(),
32
- group: 'test-group',
33
- score: 1,
34
- updated_at: new Date(),
35
- user_count: 1,
36
- activities: [],
37
- ...overrides,
38
- });
39
-
40
- describe('notification-feed-utils', () => {
41
- describe('updateNotificationFeedFromEvent', () => {
42
- it('should return unchanged if event has no notification_status or aggregated_activities', () => {
43
- const event = createMockNotificationFeedUpdatedEvent();
44
-
45
- const result = updateNotificationFeedFromEvent(event);
46
-
47
- expect(result.changed).toBe(false);
48
- });
49
-
50
- it('should update notification_status when event has notification_status', () => {
51
- const notificationStatus = createMockNotificationStatus({
52
- unread: 5,
53
- unseen: 3,
54
- read_activities: ['activity1', 'activity2'],
55
- });
56
- const event = createMockNotificationFeedUpdatedEvent({
57
- notification_status: notificationStatus,
58
- });
59
-
60
- const result = updateNotificationFeedFromEvent(event);
61
-
62
- expect(result.changed).toBe(true);
63
- expect(result.data?.notification_status).toBe(notificationStatus);
64
- expect(result.data?.aggregated_activities).toBeUndefined();
65
- });
66
-
67
- it('should update aggregated_activities when event has aggregated_activities', () => {
68
- const aggregatedActivities = [
69
- createMockAggregatedActivity({ group: 'group1' }),
70
- createMockAggregatedActivity({ group: 'group2' }),
71
- ];
72
- const event = createMockNotificationFeedUpdatedEvent({
73
- aggregated_activities: aggregatedActivities,
74
- });
75
-
76
- const result = updateNotificationFeedFromEvent(event);
77
-
78
- expect(result.changed).toBe(true);
79
- expect(result.data?.aggregated_activities).toBe(aggregatedActivities);
80
- expect(result.data?.notification_status).toBeUndefined();
81
- });
82
-
83
- it('should update both notification_status and aggregated_activities when event has both', () => {
84
- const notificationStatus = createMockNotificationStatus({
85
- unread: 2,
86
- unseen: 1,
87
- });
88
- const aggregatedActivities = [
89
- createMockAggregatedActivity({ group: 'group1' }),
90
- ];
91
- const event = createMockNotificationFeedUpdatedEvent({
92
- notification_status: notificationStatus,
93
- aggregated_activities: aggregatedActivities,
94
- });
95
-
96
- const result = updateNotificationFeedFromEvent(event);
97
-
98
- expect(result.changed).toBe(true);
99
- expect(result.data?.notification_status).toBe(notificationStatus);
100
- expect(result.data?.aggregated_activities).toBe(aggregatedActivities);
101
- });
102
-
103
- it('should handle notification_status with all fields', () => {
104
- const notificationStatus = createMockNotificationStatus({
105
- unread: 10,
106
- unseen: 5,
107
- last_seen_at: new Date('2023-01-01'),
108
- read_activities: ['activity1', 'activity2', 'activity3'],
109
- });
110
- const event = createMockNotificationFeedUpdatedEvent({
111
- notification_status: notificationStatus,
112
- });
113
-
114
- const result = updateNotificationFeedFromEvent(event);
115
-
116
- expect(result.changed).toBe(true);
117
- expect(result.data?.notification_status).toBe(notificationStatus);
118
- });
119
- });
120
- });
@@ -1,54 +0,0 @@
1
- import type { Feed } from '../../../feed';
2
- import type {
3
- AggregatedActivityResponse,
4
- NotificationFeedUpdatedEvent,
5
- NotificationStatusResponse,
6
- } from '../../../gen/models';
7
- import type { EventPayload, UpdateStateResult } from '../../../types-internal';
8
-
9
- export const updateNotificationFeedFromEvent = (
10
- event: NotificationFeedUpdatedEvent,
11
- ): UpdateStateResult<{
12
- data?: {
13
- notification_status?: NotificationStatusResponse;
14
- aggregated_activities?: AggregatedActivityResponse[];
15
- };
16
- }> => {
17
- const updates: {
18
- notification_status?: NotificationStatusResponse;
19
- aggregated_activities?: AggregatedActivityResponse[];
20
- } = {};
21
-
22
- if (event.notification_status) {
23
- updates.notification_status = event.notification_status;
24
- }
25
-
26
- if (event.aggregated_activities) {
27
- updates.aggregated_activities = event.aggregated_activities;
28
- }
29
-
30
- // Only return changed if we have actual updates
31
- if (Object.keys(updates).length > 0) {
32
- return {
33
- changed: true,
34
- data: updates,
35
- };
36
- }
37
-
38
- return {
39
- changed: false,
40
- };
41
- };
42
-
43
- export function handleNotificationFeedUpdated(
44
- this: Feed,
45
- event: EventPayload<'feeds.notification_feed.updated'>,
46
- ) {
47
- const result = updateNotificationFeedFromEvent(event);
48
- if (result.changed) {
49
- this.state.partialNext({
50
- notification_status: result.data?.notification_status,
51
- aggregated_activities: result.data?.aggregated_activities,
52
- });
53
- }
54
- }
@@ -1 +0,0 @@
1
- export * from './handle-notification-feed-updated'