@marinade.finance/notifications-ts-subscription-client 1.0.2-beta.3 → 1.0.2
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.
- package/__tests__/client.test.ts +87 -0
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +11 -7
- package/index.ts +2 -0
- package/package.json +1 -1
- package/types.ts +26 -8
package/__tests__/client.test.ts
CHANGED
|
@@ -316,6 +316,93 @@ describe('SubscriptionClient', () => {
|
|
|
316
316
|
})
|
|
317
317
|
})
|
|
318
318
|
|
|
319
|
+
describe('listBroadcastNotifications', () => {
|
|
320
|
+
it('should send GET request to /broadcast with query params', async () => {
|
|
321
|
+
const mockFetch = global.fetch as jest.Mock
|
|
322
|
+
const responseBody = [
|
|
323
|
+
{
|
|
324
|
+
id: '1',
|
|
325
|
+
notification_type: 'sam_auction',
|
|
326
|
+
inner_type: 'announcement',
|
|
327
|
+
user_id: 'broadcast',
|
|
328
|
+
scope: 'broadcast',
|
|
329
|
+
priority: 'critical',
|
|
330
|
+
title: 'Test announcement',
|
|
331
|
+
message: 'Test announcement body',
|
|
332
|
+
data: {},
|
|
333
|
+
notification_id: null,
|
|
334
|
+
relevance_until: '2025-01-15T00:00:00Z',
|
|
335
|
+
created_at: '2025-01-01T00:00:00Z',
|
|
336
|
+
},
|
|
337
|
+
]
|
|
338
|
+
mockFetch.mockResolvedValue({
|
|
339
|
+
ok: true,
|
|
340
|
+
json: () => Promise.resolve(responseBody),
|
|
341
|
+
} as Response)
|
|
342
|
+
|
|
343
|
+
const client = createSubscriptionClient({
|
|
344
|
+
base_url: 'http://localhost:3000',
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
const result = await client.listBroadcastNotifications({
|
|
348
|
+
notification_type: 'sam_auction',
|
|
349
|
+
priority: 'critical',
|
|
350
|
+
inner_type: 'announcement',
|
|
351
|
+
limit: 10,
|
|
352
|
+
offset: 5,
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
expect(result).toEqual(responseBody)
|
|
356
|
+
expect(mockFetch).toHaveBeenCalledTimes(1)
|
|
357
|
+
const [url, options] = mockFetch.mock.calls[0]
|
|
358
|
+
const parsed = new URL(url)
|
|
359
|
+
expect(parsed.pathname).toBe('/v1/notifications/broadcast')
|
|
360
|
+
expect(parsed.searchParams.get('notification_type')).toBe('sam_auction')
|
|
361
|
+
expect(parsed.searchParams.get('priority')).toBe('critical')
|
|
362
|
+
expect(parsed.searchParams.get('inner_type')).toBe('announcement')
|
|
363
|
+
expect(parsed.searchParams.get('limit')).toBe('10')
|
|
364
|
+
expect(parsed.searchParams.get('offset')).toBe('5')
|
|
365
|
+
expect(options?.method).toBe('GET')
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
it('should omit optional query params when not provided', async () => {
|
|
369
|
+
const mockFetch = global.fetch as jest.Mock
|
|
370
|
+
mockFetch.mockResolvedValue({
|
|
371
|
+
ok: true,
|
|
372
|
+
json: () => Promise.resolve([]),
|
|
373
|
+
} as Response)
|
|
374
|
+
|
|
375
|
+
const client = createSubscriptionClient({
|
|
376
|
+
base_url: 'http://localhost:3000',
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
await client.listBroadcastNotifications({})
|
|
380
|
+
|
|
381
|
+
const [url] = mockFetch.mock.calls[0]
|
|
382
|
+
expect(url).toBe('http://localhost:3000/v1/notifications/broadcast')
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
it('should throw NetworkError on HTTP error', async () => {
|
|
386
|
+
const mockFetch = global.fetch as jest.Mock
|
|
387
|
+
mockFetch.mockResolvedValue({
|
|
388
|
+
ok: false,
|
|
389
|
+
status: 500,
|
|
390
|
+
statusText: 'Internal Server Error',
|
|
391
|
+
text: () => Promise.resolve('server error'),
|
|
392
|
+
} as Response)
|
|
393
|
+
|
|
394
|
+
const client = createSubscriptionClient({
|
|
395
|
+
base_url: 'http://localhost:3000',
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
await expect(
|
|
399
|
+
client.listBroadcastNotifications({
|
|
400
|
+
notification_type: 'sam_auction',
|
|
401
|
+
}),
|
|
402
|
+
).rejects.toThrow(NetworkError)
|
|
403
|
+
})
|
|
404
|
+
})
|
|
405
|
+
|
|
319
406
|
describe('timeout', () => {
|
|
320
407
|
it('should throw NetworkError on timeout', async () => {
|
|
321
408
|
const mockFetch = global.fetch as jest.Mock
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { SubscriptionClientConfig } from './types';
|
|
|
3
3
|
export { SubscriptionClient };
|
|
4
4
|
export { subscribeMessage, unsubscribeMessage, listSubscriptionsMessage, } from './message';
|
|
5
5
|
export { NetworkError } from './types';
|
|
6
|
-
export type { Logger, SubscriptionClientConfig, SubscribeRequest, SubscribeResponse, UnsubscribeRequest, UnsubscribeResponse, ListSubscriptionsQuery, ListSubscriptionsAuth, Subscription, ListNotificationsQuery, ListBroadcastNotificationsQuery, Notification, NotificationScope, } from './types';
|
|
6
|
+
export type { Logger, SubscriptionClientConfig, SubscribeRequest, SubscribeResponse, UnsubscribeRequest, UnsubscribeResponse, ListSubscriptionsQuery, ListSubscriptionsAuth, Subscription, ListNotificationsQuery, ListBroadcastNotificationsQuery, Notification, NotificationScope, NotificationPriority, BondsEventInnerType, } from './types';
|
|
7
7
|
export declare const NOTIFICATION_TYPE_SAM_AUCTION = "sam_auction";
|
|
8
8
|
export declare const NOTIFICATION_TYPE_INSTITUTIONAL_SELECT = "institutional_select";
|
|
9
9
|
export declare function createSubscriptionClient(config: SubscriptionClientConfig): SubscriptionClient;
|
package/dist/types.d.ts
CHANGED
|
@@ -66,28 +66,32 @@ export interface Subscription {
|
|
|
66
66
|
export interface ListNotificationsQuery {
|
|
67
67
|
user_id: string;
|
|
68
68
|
notification_type?: string;
|
|
69
|
-
priority?:
|
|
70
|
-
inner_type?:
|
|
69
|
+
priority?: NotificationPriority;
|
|
70
|
+
inner_type?: BondsEventInnerType;
|
|
71
71
|
limit?: number;
|
|
72
72
|
offset?: number;
|
|
73
73
|
}
|
|
74
74
|
/** GET /v1/notifications/broadcast query (public, no auth required) */
|
|
75
75
|
export interface ListBroadcastNotificationsQuery {
|
|
76
76
|
notification_type?: string;
|
|
77
|
-
priority?:
|
|
78
|
-
inner_type?:
|
|
77
|
+
priority?: NotificationPriority;
|
|
78
|
+
inner_type?: BondsEventInnerType;
|
|
79
79
|
limit?: number;
|
|
80
80
|
offset?: number;
|
|
81
81
|
}
|
|
82
82
|
export type NotificationScope = 'broadcast' | 'individual';
|
|
83
|
+
export type NotificationPriority = 'critical' | 'warning' | 'info';
|
|
84
|
+
export type BondsEventInnerType = 'first_seen' | 'bond_removed' | 'auction_entered' | 'auction_exited' | 'cap_changed' | 'bond_underfunded_change' | 'bond_balance_change' | 'announcement' | 'version_bump' | 'sam_eligible_change';
|
|
83
85
|
/** GET /v1/notifications response item */
|
|
84
86
|
export interface Notification {
|
|
85
|
-
|
|
87
|
+
/** BIGSERIAL in PostgreSQL, serialized as string via JSON replacer */
|
|
88
|
+
id: string;
|
|
86
89
|
notification_type: string;
|
|
87
|
-
inner_type:
|
|
90
|
+
inner_type: BondsEventInnerType;
|
|
88
91
|
user_id: string;
|
|
89
92
|
scope: NotificationScope;
|
|
90
|
-
priority:
|
|
93
|
+
priority: NotificationPriority;
|
|
94
|
+
title: string | null;
|
|
91
95
|
message: string;
|
|
92
96
|
data: Record<string, unknown>;
|
|
93
97
|
notification_id: string | null;
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -87,8 +87,8 @@ export interface Subscription {
|
|
|
87
87
|
export interface ListNotificationsQuery {
|
|
88
88
|
user_id: string
|
|
89
89
|
notification_type?: string
|
|
90
|
-
priority?:
|
|
91
|
-
inner_type?:
|
|
90
|
+
priority?: NotificationPriority
|
|
91
|
+
inner_type?: BondsEventInnerType
|
|
92
92
|
limit?: number
|
|
93
93
|
offset?: number
|
|
94
94
|
}
|
|
@@ -96,23 +96,41 @@ export interface ListNotificationsQuery {
|
|
|
96
96
|
/** GET /v1/notifications/broadcast query (public, no auth required) */
|
|
97
97
|
export interface ListBroadcastNotificationsQuery {
|
|
98
98
|
notification_type?: string
|
|
99
|
-
priority?:
|
|
100
|
-
inner_type?:
|
|
99
|
+
priority?: NotificationPriority
|
|
100
|
+
inner_type?: BondsEventInnerType
|
|
101
101
|
limit?: number
|
|
102
102
|
offset?: number
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// Keep in sync with notification-service/notifications/notifications.constants.ts
|
|
105
|
+
// Keep in sync with notification-service/notifications/notifications.constants.ts
|
|
106
106
|
export type NotificationScope = 'broadcast' | 'individual'
|
|
107
107
|
|
|
108
|
+
// Keep in sync with notifications-bonds/src/types.ts NotificationPriority
|
|
109
|
+
export type NotificationPriority = 'critical' | 'warning' | 'info'
|
|
110
|
+
|
|
111
|
+
// Keep in sync with notifications-bonds-event-v1 BondsEventInnerType
|
|
112
|
+
export type BondsEventInnerType =
|
|
113
|
+
| 'first_seen'
|
|
114
|
+
| 'bond_removed'
|
|
115
|
+
| 'auction_entered'
|
|
116
|
+
| 'auction_exited'
|
|
117
|
+
| 'cap_changed'
|
|
118
|
+
| 'bond_underfunded_change'
|
|
119
|
+
| 'bond_balance_change'
|
|
120
|
+
| 'announcement'
|
|
121
|
+
| 'version_bump'
|
|
122
|
+
| 'sam_eligible_change'
|
|
123
|
+
|
|
108
124
|
/** GET /v1/notifications response item */
|
|
109
125
|
export interface Notification {
|
|
110
|
-
|
|
126
|
+
/** BIGSERIAL in PostgreSQL, serialized as string via JSON replacer */
|
|
127
|
+
id: string
|
|
111
128
|
notification_type: string
|
|
112
|
-
inner_type:
|
|
129
|
+
inner_type: BondsEventInnerType
|
|
113
130
|
user_id: string
|
|
114
131
|
scope: NotificationScope
|
|
115
|
-
priority:
|
|
132
|
+
priority: NotificationPriority
|
|
133
|
+
title: string | null
|
|
116
134
|
message: string
|
|
117
135
|
data: Record<string, unknown>
|
|
118
136
|
notification_id: string | null
|