shred-api-client 1.12.2 → 1.13.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.
@@ -1,11 +1,14 @@
1
1
  import Environment from "../model/Env";
2
- import { NotificationSchema, NotificationDetail, Trigger } from "../model/Notification.schema";
2
+ import { NotificationSchema, NotificationDetail, Trigger, NotificationItem } from "../model/Notification.schema";
3
3
  import Context from "../model/Context";
4
4
  import { APIResponse } from "../model/Api";
5
5
  declare class NotificationAPI implements NotificationSchema {
6
6
  private env;
7
7
  private clientHTTP;
8
8
  constructor(env: Environment);
9
+ clearNotifications(ctx: Context): Promise<boolean>;
10
+ markAsRead(ctx: Context, id: string): Promise<boolean>;
11
+ getNotifications(ctx: Context): Promise<APIResponse<NotificationItem>>;
9
12
  deleteTrigger(ctx: Context, triggerId: string): Promise<boolean>;
10
13
  updateTrigger(ctx: Context, triggerId: string, t: Partial<Trigger>): Promise<Trigger>;
11
14
  createTrigger(ctx: Context, t: Trigger): Promise<Trigger>;
@@ -10,6 +10,22 @@ class NotificationAPI {
10
10
  this.env = env;
11
11
  this.clientHTTP = new HTTPClient_1.default();
12
12
  }
13
+ async clearNotifications(ctx) {
14
+ const endpointData = Notification_schema_1.NotificationEndpoints.ClearNotifications;
15
+ const data = await this.clientHTTP.makeRequest(this.env, endpointData.uri, endpointData.method, null, ctx);
16
+ return data;
17
+ }
18
+ async markAsRead(ctx, id) {
19
+ const endpointData = Notification_schema_1.NotificationEndpoints.MarkAsRead;
20
+ const endpoint = endpointData.uri.replace(":id", id);
21
+ const data = await this.clientHTTP.makeRequest(this.env, endpoint, endpointData.method, null, ctx);
22
+ return data;
23
+ }
24
+ async getNotifications(ctx) {
25
+ const endpointData = Notification_schema_1.NotificationEndpoints.ListNotifications;
26
+ const data = await this.clientHTTP.makeRequest(this.env, endpointData.uri, endpointData.method, null, ctx);
27
+ return data;
28
+ }
13
29
  async deleteTrigger(ctx, triggerId) {
14
30
  const endpointData = Notification_schema_1.NotificationEndpoints.Delete;
15
31
  const endpoint = endpointData.uri.replace(":id", triggerId);
@@ -7,6 +7,9 @@ interface NotificationSchema {
7
7
  deleteTrigger: (ctx: Context, triggerId: string) => Promise<boolean>;
8
8
  updateTrigger: (ctx: Context, triggerId: string, trigger: Partial<Trigger>) => Promise<Trigger>;
9
9
  push: (context: Context, notification: NotificationDetail) => Promise<boolean>;
10
+ getNotifications: (ctx: Context) => Promise<APIResponse<NotificationItem>>;
11
+ markAsRead: (ctx: Context, id: string) => Promise<boolean>;
12
+ clearNotifications: (ctx: Context) => Promise<boolean>;
10
13
  }
11
14
  declare const NotificationEndpoints: {
12
15
  Create: {
@@ -29,6 +32,18 @@ declare const NotificationEndpoints: {
29
32
  uri: string;
30
33
  method: string;
31
34
  };
35
+ ListNotifications: {
36
+ uri: string;
37
+ method: string;
38
+ };
39
+ MarkAsRead: {
40
+ uri: string;
41
+ method: string;
42
+ };
43
+ ClearNotifications: {
44
+ uri: string;
45
+ method: string;
46
+ };
32
47
  };
33
48
  type Criteria = {
34
49
  type: Notification.CriteriaType;
@@ -82,16 +97,16 @@ type NotificationItem = {
82
97
  triggerId?: string;
83
98
  title: string;
84
99
  body: string;
85
- status: "failed" | "delivered";
100
+ status: "failed" | "delivered" | "deleted";
86
101
  deliveredAt: number;
87
102
  openedAt?: number;
103
+ deletedAt?: number;
104
+ cta?: {
105
+ label: string;
106
+ url: string;
107
+ };
88
108
  metadata: Record<string, string | number>;
89
109
  error?: string;
90
110
  };
91
- type NotificationDetail = {
92
- title: string;
93
- body: string;
94
- userToken?: string;
95
- metadata?: Record<string, any>;
96
- };
111
+ type NotificationDetail = Pick<NotificationItem, "title" | "body" | "userId" | "metadata">;
97
112
  export { NotificationItem, NotificationSchema, NotificationEndpoints, NotificationDetail, RecurrenceRule, Trigger, Criteria, History, };
@@ -22,5 +22,17 @@ const NotificationEndpoints = {
22
22
  uri: "/notifications/push/",
23
23
  method: "POST",
24
24
  },
25
+ ListNotifications: {
26
+ uri: "/notifications/list/",
27
+ method: "GET",
28
+ },
29
+ MarkAsRead: {
30
+ uri: "/notifications/:id/read/",
31
+ method: "PUT",
32
+ },
33
+ ClearNotifications: {
34
+ uri: "/notifications/clear/",
35
+ method: "DELETE",
36
+ },
25
37
  };
26
38
  exports.NotificationEndpoints = NotificationEndpoints;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shred-api-client",
3
- "version": "1.12.2",
3
+ "version": "1.13.1",
4
4
  "description": "API Client for Shred",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",