@marinade.finance/ts-subscription-client 1.0.1 → 1.0.2-beta.1
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/client.ts +31 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.js +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +22 -0
- package/index.ts +2 -0
- package/package.json +1 -1
- package/types.ts +24 -0
package/client.ts
CHANGED
|
@@ -8,10 +8,13 @@ import {
|
|
|
8
8
|
type ListSubscriptionsQuery,
|
|
9
9
|
type ListSubscriptionsAuth,
|
|
10
10
|
type Subscription,
|
|
11
|
+
type ListNotificationsQuery,
|
|
12
|
+
type Notification,
|
|
11
13
|
NetworkError,
|
|
12
14
|
} from './types'
|
|
13
15
|
|
|
14
16
|
const PATH_SUBSCRIPTIONS = '/subscriptions'
|
|
17
|
+
const PATH_NOTIFICATIONS = '/notifications'
|
|
15
18
|
|
|
16
19
|
export class SubscriptionClient {
|
|
17
20
|
private readonly base_url: string
|
|
@@ -79,6 +82,34 @@ export class SubscriptionClient {
|
|
|
79
82
|
})
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
async listNotifications(
|
|
86
|
+
query: ListNotificationsQuery,
|
|
87
|
+
): Promise<Notification[]> {
|
|
88
|
+
const params = new URLSearchParams()
|
|
89
|
+
params.set('user_id', query.user_id)
|
|
90
|
+
if (query.notification_type) {
|
|
91
|
+
params.set('notification_type', query.notification_type)
|
|
92
|
+
}
|
|
93
|
+
if (query.priority) {
|
|
94
|
+
params.set('priority', query.priority)
|
|
95
|
+
}
|
|
96
|
+
if (query.inner_type) {
|
|
97
|
+
params.set('inner_type', query.inner_type)
|
|
98
|
+
}
|
|
99
|
+
if (query.limit !== undefined) {
|
|
100
|
+
params.set('limit', query.limit.toString())
|
|
101
|
+
}
|
|
102
|
+
if (query.offset !== undefined) {
|
|
103
|
+
params.set('offset', query.offset.toString())
|
|
104
|
+
}
|
|
105
|
+
const path = `${PATH_NOTIFICATIONS}?${params.toString()}`
|
|
106
|
+
|
|
107
|
+
this.logger?.debug(`GET ${path}`)
|
|
108
|
+
return this.fetch<Notification[]>(path, {
|
|
109
|
+
method: 'GET',
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
82
113
|
private async fetch<T>(path: string, init: RequestInit): Promise<T> {
|
|
83
114
|
const url = `${this.base_url}${path}`
|
|
84
115
|
const method = init.method ?? 'GET'
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SubscriptionClientConfig, type SubscribeRequest, type SubscribeResponse, type UnsubscribeRequest, type UnsubscribeResponse, type ListSubscriptionsQuery, type ListSubscriptionsAuth, type Subscription } from './types';
|
|
1
|
+
import { type SubscriptionClientConfig, type SubscribeRequest, type SubscribeResponse, type UnsubscribeRequest, type UnsubscribeResponse, type ListSubscriptionsQuery, type ListSubscriptionsAuth, type Subscription, type ListNotificationsQuery, type Notification } from './types';
|
|
2
2
|
export declare class SubscriptionClient {
|
|
3
3
|
private readonly base_url;
|
|
4
4
|
private readonly timeout_ms;
|
|
@@ -7,5 +7,6 @@ export declare class SubscriptionClient {
|
|
|
7
7
|
subscribe(request: SubscribeRequest): Promise<SubscribeResponse>;
|
|
8
8
|
unsubscribe(request: UnsubscribeRequest): Promise<UnsubscribeResponse>;
|
|
9
9
|
listSubscriptions(query: ListSubscriptionsQuery, auth: ListSubscriptionsAuth): Promise<Subscription[]>;
|
|
10
|
+
listNotifications(query: ListNotificationsQuery): Promise<Notification[]>;
|
|
10
11
|
private fetch;
|
|
11
12
|
}
|
package/dist/client.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SubscriptionClient = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const PATH_SUBSCRIPTIONS = '/subscriptions';
|
|
6
|
+
const PATH_NOTIFICATIONS = '/notifications';
|
|
6
7
|
class SubscriptionClient {
|
|
7
8
|
constructor(config) {
|
|
8
9
|
this.base_url = config.base_url;
|
|
@@ -51,6 +52,30 @@ class SubscriptionClient {
|
|
|
51
52
|
},
|
|
52
53
|
});
|
|
53
54
|
}
|
|
55
|
+
async listNotifications(query) {
|
|
56
|
+
const params = new URLSearchParams();
|
|
57
|
+
params.set('user_id', query.user_id);
|
|
58
|
+
if (query.notification_type) {
|
|
59
|
+
params.set('notification_type', query.notification_type);
|
|
60
|
+
}
|
|
61
|
+
if (query.priority) {
|
|
62
|
+
params.set('priority', query.priority);
|
|
63
|
+
}
|
|
64
|
+
if (query.inner_type) {
|
|
65
|
+
params.set('inner_type', query.inner_type);
|
|
66
|
+
}
|
|
67
|
+
if (query.limit !== undefined) {
|
|
68
|
+
params.set('limit', query.limit.toString());
|
|
69
|
+
}
|
|
70
|
+
if (query.offset !== undefined) {
|
|
71
|
+
params.set('offset', query.offset.toString());
|
|
72
|
+
}
|
|
73
|
+
const path = `${PATH_NOTIFICATIONS}?${params.toString()}`;
|
|
74
|
+
this.logger?.debug(`GET ${path}`);
|
|
75
|
+
return this.fetch(path, {
|
|
76
|
+
method: 'GET',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
54
79
|
async fetch(path, init) {
|
|
55
80
|
const url = `${this.base_url}${path}`;
|
|
56
81
|
const method = init.method ?? 'GET';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ 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, } from './types';
|
|
6
|
+
export type { Logger, SubscriptionClientConfig, SubscribeRequest, SubscribeResponse, UnsubscribeRequest, UnsubscribeResponse, ListSubscriptionsQuery, ListSubscriptionsAuth, Subscription, ListNotificationsQuery, Notification, } from './types';
|
|
7
7
|
export declare const NOTIFICATION_TYPE_SAM_AUCTION = "sam_auction";
|
|
8
8
|
export declare function createSubscriptionClient(config: SubscriptionClientConfig): SubscriptionClient;
|
package/dist/types.d.ts
CHANGED
|
@@ -62,6 +62,28 @@ export interface Subscription {
|
|
|
62
62
|
created_at: string;
|
|
63
63
|
telegram_status?: 'pending' | 'active' | 'inactive' | 'unsubscribed' | 'blocked';
|
|
64
64
|
}
|
|
65
|
+
/** GET /notifications query (public, no auth required) */
|
|
66
|
+
export interface ListNotificationsQuery {
|
|
67
|
+
user_id: string;
|
|
68
|
+
notification_type?: string;
|
|
69
|
+
priority?: string;
|
|
70
|
+
inner_type?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
offset?: number;
|
|
73
|
+
}
|
|
74
|
+
/** GET /notifications response item */
|
|
75
|
+
export interface Notification {
|
|
76
|
+
id: number;
|
|
77
|
+
notification_type: string;
|
|
78
|
+
inner_type: string;
|
|
79
|
+
user_id: string;
|
|
80
|
+
priority: string;
|
|
81
|
+
message: string;
|
|
82
|
+
data: Record<string, unknown>;
|
|
83
|
+
notification_id: string | null;
|
|
84
|
+
relevance_until: string;
|
|
85
|
+
created_at: string;
|
|
86
|
+
}
|
|
65
87
|
export declare class NetworkError extends Error {
|
|
66
88
|
readonly status?: number | undefined;
|
|
67
89
|
readonly response?: unknown | undefined;
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -83,6 +83,30 @@ export interface Subscription {
|
|
|
83
83
|
| 'blocked'
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** GET /notifications query (public, no auth required) */
|
|
87
|
+
export interface ListNotificationsQuery {
|
|
88
|
+
user_id: string
|
|
89
|
+
notification_type?: string
|
|
90
|
+
priority?: string
|
|
91
|
+
inner_type?: string
|
|
92
|
+
limit?: number
|
|
93
|
+
offset?: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** GET /notifications response item */
|
|
97
|
+
export interface Notification {
|
|
98
|
+
id: number
|
|
99
|
+
notification_type: string
|
|
100
|
+
inner_type: string
|
|
101
|
+
user_id: string
|
|
102
|
+
priority: string
|
|
103
|
+
message: string
|
|
104
|
+
data: Record<string, unknown>
|
|
105
|
+
notification_id: string | null
|
|
106
|
+
relevance_until: string
|
|
107
|
+
created_at: string
|
|
108
|
+
}
|
|
109
|
+
|
|
86
110
|
export class NetworkError extends Error {
|
|
87
111
|
constructor(
|
|
88
112
|
message: string,
|