1 import { HttpTypes } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class Notification {
6 /**
7 * @ignore
8 */
9 private client: Client
10 /**
11 * @ignore
12 */
13 constructor(client: Client) {
14 this.client = client
15 }
16
17 /**
18 * This method retrieves a notification's details. It sends a request to the
19 * [Get Notification](https://docs.medusajs.com/api/admin/notifications/get-a-notification)
20 * API route.
21 *
22 * @param id - The notification's ID.
23 * @param query - Configure the fields to retrieve in the notification.
24 * @param headers - Headers to pass in the request
25 * @returns The notification's details.
26 *
27 * @example
28 * To retrieve a notification by its ID:
29 *
30 * ```ts
31 * sdk.admin.notification.retrieve("notif_123")
32 * .then(({ notification }) => {
33 * console.log(notification)
34 * })
35 * ```
36 *
37 * To specify the fields and relations to retrieve:
38 *
39 * ```ts
40 * sdk.admin.notification.retrieve("notif_123", {
41 * fields: "id,to"
42 * })
43 * .then(({ notification }) => {
44 * console.log(notification)
45 * })
46 * ```
47 *
48 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
49 */
50 async retrieve(
51 id: string,
52 query?: HttpTypes.AdminNotificationParams,
53 headers?: ClientHeaders
54 ) {
55 return await this.client.fetch<HttpTypes.AdminNotificationResponse>(
56 `/admin/notifications/${id}`,
57 {
58 method: "GET",
59 headers,
60 query,
61 }
62 )
63 }
64
65 /**
66 * This method retrieves a paginated list of notifications. It sends a request to the
67 * [List Notifications](https://docs.medusajs.com/api/admin/notifications/list-notifications)
68 * API route.
69 *
70 * @param query - Filters and pagination configurations.
71 * @param headers - Headers to pass in the request.
72 * @returns The paginated list of notifications.
73 *
74 * @example
75 * To retrieve the list of notifications:
76 *
77 * ```ts
78 * sdk.admin.notification.list()
79 * .then(({ notifications, count, limit, offset }) => {
80 * console.log(notifications)
81 * })
82 * ```
83 *
84 * To configure the pagination, pass the `limit` and `offset` query parameters.
85 *
86 * For example, to retrieve only 10 items and skip 10 items:
87 *
88 * ```ts
89 * sdk.admin.notification.list({
90 * limit: 10,
91 * offset: 10
92 * })
93 * .then(({ notifications, count, limit, offset }) => {
94 * console.log(notifications)
95 * })
96 * ```
97 *
98 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
99 * in each notification:
100 *
101 * ```ts
102 * sdk.admin.notification.list({
103 * fields: "id,to"
104 * })
105 * .then(({ notifications, count, limit, offset }) => {
106 * console.log(notifications)
107 * })
108 * ```
109 *
110 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
111 */
112 async list(
113 query?: HttpTypes.AdminNotificationListParams,
114 headers?: ClientHeaders
115 ) {
116 return await this.client.fetch<HttpTypes.AdminNotificationListResponse>(
117 `/admin/notifications`,
118 {
119 method: "GET",
120 headers,
121 query,
122 }
123 )
124 }
125 }