@ogcio/building-blocks-sdk 0.2.90 → 0.2.92

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.
@@ -3,6 +3,31 @@ import type { Logger } from "../../../types/index.js";
3
3
  import { formatError, formatResponse } from "../../utils/client-utils.js";
4
4
  import type { paths } from "./schema.js";
5
5
 
6
+ type ListAnnouncementsQuery =
7
+ paths["/api/v1/support/announcements/"]["get"]["parameters"]["query"];
8
+ type BooleanListAnnouncementsQuery = Omit<
9
+ ListAnnouncementsQuery,
10
+ "isEnabled"
11
+ > & {
12
+ isEnabled: boolean;
13
+ };
14
+
15
+ type CreateAnnouncementBody =
16
+ paths["/api/v1/support/announcements/"]["post"]["requestBody"]["content"]["application/json"];
17
+ type TypedCreateAnnouncementBody = Omit<
18
+ CreateAnnouncementBody,
19
+ "isEnabled" | "publishDate"
20
+ > & {
21
+ isEnabled: boolean;
22
+ publishDate: Date;
23
+ };
24
+
25
+ type ToggleEnabledBody =
26
+ paths["/api/v1/support/announcements/{id}/enabled"]["patch"]["requestBody"]["content"]["application/json"];
27
+ type TypedToggleEnabledBody = Omit<ToggleEnabledBody, "isEnabled"> & {
28
+ isEnabled: boolean;
29
+ };
30
+
6
31
  export class ProfileSupport {
7
32
  constructor(
8
33
  private readonly client: ReturnType<typeof createClient<paths>>,
@@ -48,4 +73,60 @@ export class ProfileSupport {
48
73
  (reason) => formatError(reason, this.serviceName, this.logger),
49
74
  );
50
75
  }
76
+
77
+ public readonly announcements = {
78
+ list: async (queryParams: BooleanListAnnouncementsQuery) => {
79
+ let isEnabled: undefined | "true" | "false";
80
+ if (queryParams.isEnabled !== undefined) {
81
+ isEnabled = queryParams.isEnabled ? "true" : "false";
82
+ }
83
+
84
+ return this.client
85
+ .GET("/api/v1/support/announcements/", {
86
+ params: { query: { ...queryParams, isEnabled } },
87
+ })
88
+ .then(
89
+ (response) => formatResponse(response, this.serviceName, this.logger),
90
+ (reason) => formatError(reason, this.serviceName, this.logger),
91
+ );
92
+ },
93
+ create: async (body: TypedCreateAnnouncementBody) => {
94
+ return this.client
95
+ .POST("/api/v1/support/announcements/", {
96
+ body: {
97
+ ...body,
98
+ isEnabled: body.isEnabled ? "true" : "false",
99
+ publishDate: body.publishDate.toISOString(),
100
+ },
101
+ })
102
+ .then(
103
+ (response) => formatResponse(response, this.serviceName, this.logger),
104
+ (reason) => formatError(reason, this.serviceName, this.logger),
105
+ );
106
+ },
107
+ toggleEnabled: async (id: string, body: TypedToggleEnabledBody) => {
108
+ return this.client
109
+ .PATCH("/api/v1/support/announcements/{id}/enabled", {
110
+ params: { path: { id } },
111
+ body: {
112
+ ...body,
113
+ isEnabled: body.isEnabled ? "true" : "false",
114
+ },
115
+ })
116
+ .then(
117
+ (response) => formatResponse(response, this.serviceName, this.logger),
118
+ (reason) => formatError(reason, this.serviceName, this.logger),
119
+ );
120
+ },
121
+ get: async (id: string) => {
122
+ return this.client
123
+ .GET("/api/v1/support/announcements/{id}", {
124
+ params: { path: { id } },
125
+ })
126
+ .then(
127
+ (response) => formatResponse(response, this.serviceName, this.logger),
128
+ (reason) => formatError(reason, this.serviceName, this.logger),
129
+ );
130
+ },
131
+ };
51
132
  }