shred-api-client 1.12.1 → 1.13.0

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,13 @@
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
+ markAsRead(ctx: Context, id: string): Promise<boolean>;
10
+ getNotifications(ctx: Context): Promise<APIResponse<NotificationItem>>;
9
11
  deleteTrigger(ctx: Context, triggerId: string): Promise<boolean>;
10
12
  updateTrigger(ctx: Context, triggerId: string, t: Partial<Trigger>): Promise<Trigger>;
11
13
  createTrigger(ctx: Context, t: Trigger): Promise<Trigger>;
@@ -10,6 +10,17 @@ class NotificationAPI {
10
10
  this.env = env;
11
11
  this.clientHTTP = new HTTPClient_1.default();
12
12
  }
13
+ async markAsRead(ctx, id) {
14
+ const endpointData = Notification_schema_1.NotificationEndpoints.MarkAsRead;
15
+ const endpoint = endpointData.uri.replace(":id", id);
16
+ const data = await this.clientHTTP.makeRequest(this.env, endpoint, endpointData.method, null, ctx);
17
+ return data;
18
+ }
19
+ async getNotifications(ctx) {
20
+ const endpointData = Notification_schema_1.NotificationEndpoints.ListNotifications;
21
+ const data = await this.clientHTTP.makeRequest(this.env, endpointData.uri, endpointData.method, null, ctx);
22
+ return data;
23
+ }
13
24
  async deleteTrigger(ctx, triggerId) {
14
25
  const endpointData = Notification_schema_1.NotificationEndpoints.Delete;
15
26
  const endpoint = endpointData.uri.replace(":id", triggerId);
@@ -7,6 +7,8 @@ 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>;
10
12
  }
11
13
  declare const NotificationEndpoints: {
12
14
  Create: {
@@ -29,6 +31,14 @@ declare const NotificationEndpoints: {
29
31
  uri: string;
30
32
  method: string;
31
33
  };
34
+ ListNotifications: {
35
+ uri: string;
36
+ method: string;
37
+ };
38
+ MarkAsRead: {
39
+ uri: string;
40
+ method: string;
41
+ };
32
42
  };
33
43
  type Criteria = {
34
44
  type: Notification.CriteriaType;
@@ -44,7 +54,10 @@ type History = {
44
54
  success: number;
45
55
  error: number;
46
56
  };
47
- errorList?: string[];
57
+ errorList?: {
58
+ token: string;
59
+ error: string;
60
+ }[];
48
61
  executionTimeDuration?: number;
49
62
  };
50
63
  type RecurrenceRule = {
@@ -73,10 +86,17 @@ type Trigger = {
73
86
  createdAt?: number;
74
87
  modified?: number;
75
88
  };
76
- type NotificationDetail = {
89
+ type NotificationItem = {
90
+ id: string;
91
+ userId: string;
92
+ triggerId?: string;
77
93
  title: string;
78
94
  body: string;
79
- userToken?: string;
80
- metadata?: Record<string, any>;
95
+ status: "failed" | "delivered";
96
+ deliveredAt: number;
97
+ openedAt?: number;
98
+ metadata: Record<string, string | number>;
99
+ error?: string;
81
100
  };
82
- export { NotificationSchema, NotificationEndpoints, NotificationDetail, RecurrenceRule, Trigger, Criteria, History, };
101
+ type NotificationDetail = Pick<NotificationItem, "title" | "body" | "userId" | "metadata">;
102
+ export { NotificationItem, NotificationSchema, NotificationEndpoints, NotificationDetail, RecurrenceRule, Trigger, Criteria, History, };
@@ -22,5 +22,13 @@ 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
+ },
25
33
  };
26
34
  exports.NotificationEndpoints = NotificationEndpoints;
@@ -1,5 +1,5 @@
1
1
  import { Product as TProduct, Subscription as TSubscription, Charge as TCharge } from "./model/Subscription.schema";
2
- import { Trigger as TTrigger, Criteria as TCriteria, NotificationDetail as TNContent, RecurrenceRule as TRRule, History as THistory } from "./model/Notification.schema";
2
+ import { Trigger as TTrigger, Criteria as TCriteria, NotificationDetail as TNContent, RecurrenceRule as TRRule, NotificationItem as TNotificaitonItem, History as THistory } from "./model/Notification.schema";
3
3
  import { APIResponse } from "./model/Api";
4
4
  import { System as TSystem, User as TUser, Preferences as UserPreferences, Role as TRole } from "./model/User.schema";
5
5
  import { Email as TEmail } from "./model/Email.schema";
@@ -69,6 +69,7 @@ export declare namespace Notification {
69
69
  type Trigger = TTrigger;
70
70
  type Criteria = TCriteria;
71
71
  type History = THistory;
72
+ type Item = TNotificaitonItem;
72
73
  type Detail = TNContent;
73
74
  }
74
75
  export declare namespace User {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shred-api-client",
3
- "version": "1.12.1",
3
+ "version": "1.13.0",
4
4
  "description": "API Client for Shred",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",