@ogcio/building-blocks-sdk 0.0.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/.husky/commit-msg +1 -0
- package/.husky/pre-push +1 -0
- package/.nvmrc +1 -0
- package/.vscode/settings.json +20 -0
- package/biome.jsonc +45 -0
- package/commitlint.config.js +6 -0
- package/dist/client/auth/index.d.ts +4 -0
- package/dist/client/auth/index.d.ts.map +1 -0
- package/dist/client/auth/index.js +83 -0
- package/dist/client/auth/index.js.map +1 -0
- package/dist/client/base-client.d.ts +18 -0
- package/dist/client/base-client.d.ts.map +1 -0
- package/dist/client/base-client.js +71 -0
- package/dist/client/base-client.js.map +1 -0
- package/dist/client/clients/messaging/index.d.ts +2407 -0
- package/dist/client/clients/messaging/index.d.ts.map +1 -0
- package/dist/client/clients/messaging/index.js +430 -0
- package/dist/client/clients/messaging/index.js.map +1 -0
- package/dist/client/clients/messaging/schema.d.ts +3823 -0
- package/dist/client/clients/messaging/schema.d.ts.map +1 -0
- package/dist/client/clients/messaging/schema.js +2 -0
- package/dist/client/clients/messaging/schema.js.map +1 -0
- package/dist/client/clients/payments/index.d.ts +2294 -0
- package/dist/client/clients/payments/index.d.ts.map +1 -0
- package/dist/client/clients/payments/index.js +217 -0
- package/dist/client/clients/payments/index.js.map +1 -0
- package/dist/client/clients/payments/schema.d.ts +2534 -0
- package/dist/client/clients/payments/schema.d.ts.map +1 -0
- package/dist/client/clients/payments/schema.js +2 -0
- package/dist/client/clients/payments/schema.js.map +1 -0
- package/dist/client/clients/profile/index.d.ts +1364 -0
- package/dist/client/clients/profile/index.d.ts.map +1 -0
- package/dist/client/clients/profile/index.js +102 -0
- package/dist/client/clients/profile/index.js.map +1 -0
- package/dist/client/clients/profile/schema.d.ts +1429 -0
- package/dist/client/clients/profile/schema.d.ts.map +1 -0
- package/dist/client/clients/profile/schema.js +2 -0
- package/dist/client/clients/profile/schema.js.map +1 -0
- package/dist/client/clients/scheduler/index.d.ts +14 -0
- package/dist/client/clients/scheduler/index.d.ts.map +1 -0
- package/dist/client/clients/scheduler/index.js +14 -0
- package/dist/client/clients/scheduler/index.js.map +1 -0
- package/dist/client/clients/scheduler/schema.d.ts +114 -0
- package/dist/client/clients/scheduler/schema.d.ts.map +1 -0
- package/dist/client/clients/scheduler/schema.js +2 -0
- package/dist/client/clients/scheduler/schema.js.map +1 -0
- package/dist/client/clients/upload/index.d.ts +390 -0
- package/dist/client/clients/upload/index.d.ts.map +1 -0
- package/dist/client/clients/upload/index.js +93 -0
- package/dist/client/clients/upload/index.js.map +1 -0
- package/dist/client/clients/upload/schema.d.ts +564 -0
- package/dist/client/clients/upload/schema.d.ts.map +1 -0
- package/dist/client/clients/upload/schema.js +2 -0
- package/dist/client/clients/upload/schema.js.map +1 -0
- package/dist/client/utils/client-utils.d.ts +15 -0
- package/dist/client/utils/client-utils.d.ts.map +1 -0
- package/dist/client/utils/client-utils.js +14 -0
- package/dist/client/utils/client-utils.js.map +1 -0
- package/dist/clients-configurations/clients-configuration.json +92 -0
- package/dist/clients-configurations/read-configuration-file.d.ts +22 -0
- package/dist/clients-configurations/read-configuration-file.d.ts.map +1 -0
- package/dist/clients-configurations/read-configuration-file.js +47 -0
- package/dist/clients-configurations/read-configuration-file.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/get-absolute-path.d.ts +3 -0
- package/dist/utils/get-absolute-path.d.ts.map +1 -0
- package/dist/utils/get-absolute-path.js +8 -0
- package/dist/utils/get-absolute-path.js.map +1 -0
- package/package.json +44 -0
- package/src/cli/cli-utils.ts +25 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/outdated-clients-command.ts +148 -0
- package/src/cli/update-clients-command.ts +298 -0
- package/src/client/auth/index.ts +131 -0
- package/src/client/base-client.ts +97 -0
- package/src/client/clients/messaging/index.ts +683 -0
- package/src/client/clients/messaging/open-api-definition.json +8394 -0
- package/src/client/clients/messaging/schema.ts +3822 -0
- package/src/client/clients/payments/index.ts +349 -0
- package/src/client/clients/payments/open-api-definition.json +6094 -0
- package/src/client/clients/payments/schema.ts +2533 -0
- package/src/client/clients/profile/index.ts +182 -0
- package/src/client/clients/profile/open-api-definition.json +2876 -0
- package/src/client/clients/profile/schema.ts +1428 -0
- package/src/client/clients/scheduler/index.ts +28 -0
- package/src/client/clients/scheduler/open-api-definition.json +120 -0
- package/src/client/clients/scheduler/schema.ts +113 -0
- package/src/client/clients/upload/index.ts +129 -0
- package/src/client/clients/upload/open-api-definition.json +985 -0
- package/src/client/clients/upload/schema.ts +563 -0
- package/src/client/utils/client-utils.ts +50 -0
- package/src/clients-configurations/clients-configuration.json +92 -0
- package/src/clients-configurations/read-configuration-file.ts +68 -0
- package/src/index.ts +43 -0
- package/src/logto-node.d.ts +12 -0
- package/src/types/index.ts +82 -0
- package/src/utils/get-absolute-path.ts +10 -0
- package/tsconfig.json +18 -0
- package/tsconfig.prod.json +4 -0
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
import createError from "http-errors";
|
|
2
|
+
import type createClient from "openapi-fetch";
|
|
3
|
+
import { MESSAGING } from "../../../types/index.js";
|
|
4
|
+
import BaseClient from "../../base-client.js";
|
|
5
|
+
import {
|
|
6
|
+
type PaginationParams,
|
|
7
|
+
preparePaginationParams,
|
|
8
|
+
toStringOrUndefined,
|
|
9
|
+
} from "../../utils/client-utils.js";
|
|
10
|
+
import type { paths } from "./schema.js";
|
|
11
|
+
|
|
12
|
+
class Messaging extends BaseClient<paths> {
|
|
13
|
+
declare client: ReturnType<typeof createClient<paths>>;
|
|
14
|
+
protected serviceName = MESSAGING;
|
|
15
|
+
|
|
16
|
+
async getMessagesForUser(
|
|
17
|
+
userId: string,
|
|
18
|
+
filter?: {
|
|
19
|
+
isSeen?: boolean;
|
|
20
|
+
search?: string;
|
|
21
|
+
} & PaginationParams,
|
|
22
|
+
) {
|
|
23
|
+
const isSeen =
|
|
24
|
+
filter?.isSeen === undefined
|
|
25
|
+
? undefined
|
|
26
|
+
: filter.isSeen
|
|
27
|
+
? "true"
|
|
28
|
+
: "false";
|
|
29
|
+
return this.client
|
|
30
|
+
.GET("/api/v1/messages/", {
|
|
31
|
+
params: {
|
|
32
|
+
query: {
|
|
33
|
+
...preparePaginationParams(filter),
|
|
34
|
+
recipientUserId: userId,
|
|
35
|
+
status: "delivered",
|
|
36
|
+
isSeen,
|
|
37
|
+
search: filter?.search,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
.then(
|
|
42
|
+
(response) => this.formatResponse(response),
|
|
43
|
+
(reason) => this.formatError(reason),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getMessagesForOrganisation(
|
|
48
|
+
organisationId: string,
|
|
49
|
+
filter?: PaginationParams,
|
|
50
|
+
) {
|
|
51
|
+
return this.client
|
|
52
|
+
.GET("/api/v1/messages/", {
|
|
53
|
+
params: {
|
|
54
|
+
query: {
|
|
55
|
+
...preparePaginationParams(filter),
|
|
56
|
+
organisationId,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
.then(
|
|
61
|
+
(response) => this.formatResponse(response),
|
|
62
|
+
(reason) => this.formatError(reason),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getMessage(
|
|
67
|
+
messageId: paths["/api/v1/messages/{messageId}"]["get"]["parameters"]["path"]["messageId"],
|
|
68
|
+
) {
|
|
69
|
+
return this.client
|
|
70
|
+
.GET("/api/v1/messages/{messageId}", {
|
|
71
|
+
params: { path: { messageId } },
|
|
72
|
+
})
|
|
73
|
+
.then(
|
|
74
|
+
(response) => this.formatResponse(response),
|
|
75
|
+
(reason) => this.formatError(reason),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async send(
|
|
80
|
+
body: paths["/api/v1/messages/"]["post"]["requestBody"]["content"]["application/json"],
|
|
81
|
+
) {
|
|
82
|
+
return this.client
|
|
83
|
+
.POST("/api/v1/messages/", {
|
|
84
|
+
body,
|
|
85
|
+
})
|
|
86
|
+
.then(
|
|
87
|
+
(response) => this.formatResponse(response),
|
|
88
|
+
(reason) => this.formatError(reason),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getTemplates(filter?: PaginationParams) {
|
|
93
|
+
return this.client
|
|
94
|
+
.GET("/api/v1/templates/", {
|
|
95
|
+
params: {
|
|
96
|
+
query: {
|
|
97
|
+
...preparePaginationParams(filter),
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
.then(
|
|
102
|
+
(response) => this.formatResponse(response),
|
|
103
|
+
(reason) => this.formatError(reason),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async getTemplate(
|
|
108
|
+
templateId: paths["/api/v1/templates/{templateId}"]["get"]["parameters"]["path"]["templateId"],
|
|
109
|
+
) {
|
|
110
|
+
return this.client
|
|
111
|
+
.GET("/api/v1/templates/{templateId}", {
|
|
112
|
+
params: {
|
|
113
|
+
path: {
|
|
114
|
+
templateId,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
.then(
|
|
119
|
+
(response) => this.formatResponse(response),
|
|
120
|
+
(reason) => this.formatError(reason),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async buildMessage(
|
|
125
|
+
messages: paths["/api/v1/messages/"]["post"]["requestBody"]["content"]["application/json"]["message"][],
|
|
126
|
+
language: string,
|
|
127
|
+
vars: Record<string, string | null | undefined>,
|
|
128
|
+
) {
|
|
129
|
+
if (language.length === 0) {
|
|
130
|
+
throw createError.BadRequest("no language provided");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const message = messages.find((m) => m.language === language);
|
|
134
|
+
|
|
135
|
+
if (!message) {
|
|
136
|
+
throw createError.NotFound(`template not found for language ${language}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const illegalValueKeys: string[] = [];
|
|
140
|
+
const keys = Object.keys(vars);
|
|
141
|
+
for (const key of keys) {
|
|
142
|
+
if (vars[key] === null || vars[key] === undefined) {
|
|
143
|
+
illegalValueKeys.push(key);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (illegalValueKeys.length) {
|
|
148
|
+
throw createError.BadRequest(
|
|
149
|
+
`illegal empty variables ${illegalValueKeys.join(", ")}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// No null | undefined at this point
|
|
154
|
+
const interpolator = this.newInterpolator(vars as Record<string, string>);
|
|
155
|
+
|
|
156
|
+
const textVariables = new Set<string>();
|
|
157
|
+
for (const text of [
|
|
158
|
+
message.subject,
|
|
159
|
+
message.excerpt,
|
|
160
|
+
message.richText,
|
|
161
|
+
message.plainText,
|
|
162
|
+
]) {
|
|
163
|
+
(text.match(/[^{{]+(?=}})/g) || []).forEach(
|
|
164
|
+
textVariables.add,
|
|
165
|
+
textVariables,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check all content if there's any unhandled vars.
|
|
170
|
+
const illegalVariables: string[] = [];
|
|
171
|
+
for (const val of textVariables) {
|
|
172
|
+
if (!keys.some((key) => key === val)) {
|
|
173
|
+
illegalVariables.push(val);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (illegalVariables.length) {
|
|
178
|
+
throw createError.BadRequest(
|
|
179
|
+
`illegal template variables ${illegalVariables.join(", ")}`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
threadName: message.threadName,
|
|
185
|
+
subject: keys.reduce(interpolator, message.subject),
|
|
186
|
+
excerpt: keys.reduce(interpolator, message.excerpt),
|
|
187
|
+
richText: keys.reduce(interpolator, message.richText),
|
|
188
|
+
plainText: keys.reduce(interpolator, message.plainText),
|
|
189
|
+
language: message.language,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async createTemplate(
|
|
194
|
+
body: paths["/api/v1/templates/"]["post"]["requestBody"]["content"]["application/json"],
|
|
195
|
+
) {
|
|
196
|
+
return this.client.POST("/api/v1/templates/", { body }).then(
|
|
197
|
+
(response) => this.formatResponse(response),
|
|
198
|
+
(reason) => this.formatError(reason),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async updateTemplate(
|
|
203
|
+
templateId: paths["/api/v1/templates/{templateId}"]["put"]["parameters"]["path"]["templateId"],
|
|
204
|
+
body: paths["/api/v1/templates/{templateId}"]["put"]["requestBody"]["content"]["application/json"],
|
|
205
|
+
) {
|
|
206
|
+
return this.client
|
|
207
|
+
.PUT("/api/v1/templates/{templateId}", {
|
|
208
|
+
params: { path: { templateId } },
|
|
209
|
+
body,
|
|
210
|
+
})
|
|
211
|
+
.then(
|
|
212
|
+
(response) => this.formatResponse(response),
|
|
213
|
+
(reason) => this.formatError(reason),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async deleteTemplate(
|
|
218
|
+
templateId: paths["/api/v1/templates/{templateId}"]["delete"]["parameters"]["path"]["templateId"],
|
|
219
|
+
) {
|
|
220
|
+
return this.client
|
|
221
|
+
.DELETE("/api/v1/templates/{templateId}", {
|
|
222
|
+
params: { path: { templateId } },
|
|
223
|
+
})
|
|
224
|
+
.then(
|
|
225
|
+
(response) => this.formatResponse(response),
|
|
226
|
+
(reason) => this.formatError(reason),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async getEmailProviders(
|
|
231
|
+
params?: {
|
|
232
|
+
primary?: boolean;
|
|
233
|
+
} & PaginationParams,
|
|
234
|
+
) {
|
|
235
|
+
const { primary } = params || {};
|
|
236
|
+
const { error, data } = await this.client.GET("/api/v1/providers/", {
|
|
237
|
+
params: {
|
|
238
|
+
query: {
|
|
239
|
+
type: "email",
|
|
240
|
+
...preparePaginationParams(params),
|
|
241
|
+
primary:
|
|
242
|
+
primary !== undefined ? (primary ? "true" : "false") : undefined,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
error,
|
|
249
|
+
data: data?.data
|
|
250
|
+
.filter((item: { type?: string }) => item.type === "email")
|
|
251
|
+
.map(
|
|
252
|
+
(item: { id: string; providerName: string; isPrimary: boolean }) => ({
|
|
253
|
+
id: item.id,
|
|
254
|
+
providerName: item.providerName,
|
|
255
|
+
isPrimary: item.isPrimary,
|
|
256
|
+
}),
|
|
257
|
+
),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async getEmailProvider(providerId: string) {
|
|
262
|
+
const { data, error } = await this.client.GET(
|
|
263
|
+
"/api/v1/providers/{providerId}",
|
|
264
|
+
{
|
|
265
|
+
params: { path: { providerId }, query: { type: "email" } },
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
if (data?.data.type === "email") {
|
|
270
|
+
return { data: data.data };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return { error };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async createEmailProvider(provider: {
|
|
277
|
+
providerName: string;
|
|
278
|
+
isPrimary: boolean;
|
|
279
|
+
smtpHost: string;
|
|
280
|
+
smtpPort: number;
|
|
281
|
+
username: string;
|
|
282
|
+
password: string;
|
|
283
|
+
throttle?: number;
|
|
284
|
+
fromAddress: string;
|
|
285
|
+
ssl: boolean;
|
|
286
|
+
}) {
|
|
287
|
+
return this.client
|
|
288
|
+
.POST("/api/v1/providers/", {
|
|
289
|
+
body: {
|
|
290
|
+
type: "email",
|
|
291
|
+
...provider,
|
|
292
|
+
},
|
|
293
|
+
})
|
|
294
|
+
.then(
|
|
295
|
+
(response) => this.formatResponse(response),
|
|
296
|
+
(reason) => this.formatError(reason),
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async updateEmailProvider(provider: {
|
|
301
|
+
id: string;
|
|
302
|
+
providerName: string;
|
|
303
|
+
isPrimary: boolean;
|
|
304
|
+
smtpHost: string;
|
|
305
|
+
smtpPort: number;
|
|
306
|
+
username: string;
|
|
307
|
+
password: string;
|
|
308
|
+
throttle?: number;
|
|
309
|
+
fromAddress: string;
|
|
310
|
+
ssl: boolean;
|
|
311
|
+
}) {
|
|
312
|
+
return this.client
|
|
313
|
+
.PUT("/api/v1/providers/{providerId}", {
|
|
314
|
+
params: { path: { providerId: provider.id } },
|
|
315
|
+
body: {
|
|
316
|
+
type: "email",
|
|
317
|
+
...provider,
|
|
318
|
+
},
|
|
319
|
+
})
|
|
320
|
+
.then(
|
|
321
|
+
(response) => this.formatResponse(response),
|
|
322
|
+
(reason) => this.formatError(reason),
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async deleteEmailProvider(providerId: string) {
|
|
327
|
+
return this.client
|
|
328
|
+
.DELETE("/api/v1/providers/{providerId}", {
|
|
329
|
+
params: { path: { providerId } },
|
|
330
|
+
})
|
|
331
|
+
.then(
|
|
332
|
+
(response) => this.formatResponse(response),
|
|
333
|
+
(reason) => this.formatError(reason),
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async getSmsProviders(
|
|
338
|
+
params?: {
|
|
339
|
+
primary?: boolean;
|
|
340
|
+
} & PaginationParams,
|
|
341
|
+
) {
|
|
342
|
+
const { primary } = params || {};
|
|
343
|
+
const { error, data } = await this.client.GET("/api/v1/providers/", {
|
|
344
|
+
params: {
|
|
345
|
+
query: {
|
|
346
|
+
type: "sms",
|
|
347
|
+
...preparePaginationParams(params),
|
|
348
|
+
primary:
|
|
349
|
+
primary !== undefined ? (primary ? "true" : "false") : undefined,
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
error,
|
|
356
|
+
data: data?.data
|
|
357
|
+
.filter((item: { type?: string }) => item.type === "sms")
|
|
358
|
+
.map(
|
|
359
|
+
(item: { id: string; providerName: string; isPrimary: boolean }) => ({
|
|
360
|
+
id: item.id,
|
|
361
|
+
providerName: item.providerName,
|
|
362
|
+
isPrimary: item.isPrimary,
|
|
363
|
+
}),
|
|
364
|
+
),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async getSmsProvider(providerId: string) {
|
|
369
|
+
const { data, error } = await this.client.GET(
|
|
370
|
+
"/api/v1/providers/{providerId}",
|
|
371
|
+
{
|
|
372
|
+
params: { path: { providerId }, query: { type: "sms" } },
|
|
373
|
+
},
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
// Let's do some type plumbing for the implementor
|
|
377
|
+
if (data?.data.type === "sms") {
|
|
378
|
+
return { data: data.data };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Can we throw or return a new NotFoundError here?
|
|
382
|
+
return { error };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async updateSmsProvider(provider: {
|
|
386
|
+
id: string;
|
|
387
|
+
providerName: string;
|
|
388
|
+
isPrimary: boolean;
|
|
389
|
+
// Union other config types
|
|
390
|
+
config: {
|
|
391
|
+
type: "AWS";
|
|
392
|
+
accessKey: string;
|
|
393
|
+
secretAccessKey: string;
|
|
394
|
+
region: string;
|
|
395
|
+
};
|
|
396
|
+
}) {
|
|
397
|
+
return this.client
|
|
398
|
+
.PUT("/api/v1/providers/{providerId}", {
|
|
399
|
+
params: { path: { providerId: provider.id } },
|
|
400
|
+
body: {
|
|
401
|
+
type: "sms",
|
|
402
|
+
...provider,
|
|
403
|
+
},
|
|
404
|
+
})
|
|
405
|
+
.then(
|
|
406
|
+
(response) => this.formatResponse(response),
|
|
407
|
+
(reason) => this.formatError(reason),
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async createSmsProvider(provider: {
|
|
412
|
+
providerName: string;
|
|
413
|
+
isPrimary: boolean;
|
|
414
|
+
// Union other config types
|
|
415
|
+
config: {
|
|
416
|
+
type: "AWS";
|
|
417
|
+
accessKey: string;
|
|
418
|
+
secretAccessKey: string;
|
|
419
|
+
region: string;
|
|
420
|
+
};
|
|
421
|
+
}) {
|
|
422
|
+
return this.client
|
|
423
|
+
.POST("/api/v1/providers/", {
|
|
424
|
+
body: {
|
|
425
|
+
type: "sms",
|
|
426
|
+
...provider,
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
.then(
|
|
430
|
+
(response) => this.formatResponse(response),
|
|
431
|
+
(reason) => this.formatError(reason),
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async deleteSmsProvider(providerId: string) {
|
|
436
|
+
return this.client
|
|
437
|
+
.DELETE("/api/v1/providers/{providerId}", {
|
|
438
|
+
params: { path: { providerId } },
|
|
439
|
+
})
|
|
440
|
+
.then(
|
|
441
|
+
(response) => this.formatResponse(response),
|
|
442
|
+
(reason) => this.formatError(reason),
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async importUsers(toImport: { file?: File; records?: object[] }) {
|
|
447
|
+
if (toImport.file) {
|
|
448
|
+
const { data, error } = await this.client.POST("/api/v1/user-imports/", {
|
|
449
|
+
body: {
|
|
450
|
+
file: toImport.file,
|
|
451
|
+
},
|
|
452
|
+
bodySerializer: (body: unknown) => {
|
|
453
|
+
const parsed = body as { file?: File } | undefined;
|
|
454
|
+
if (!parsed || !parsed.file) {
|
|
455
|
+
throw createError.BadRequest("File is missing!");
|
|
456
|
+
}
|
|
457
|
+
const formData = new FormData();
|
|
458
|
+
formData.set("file", parsed.file);
|
|
459
|
+
return formData;
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
return { data: data?.data, error };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return this.client
|
|
466
|
+
.POST("/api/v1/user-imports/", {
|
|
467
|
+
body: toImport.records,
|
|
468
|
+
})
|
|
469
|
+
.then(
|
|
470
|
+
(response) => this.formatResponse(response),
|
|
471
|
+
(reason) => this.formatError(reason),
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async downloadUsersCsvTemplate() {
|
|
476
|
+
return this.client
|
|
477
|
+
.GET("/api/v1/user-imports/template-download", {
|
|
478
|
+
parseAs: "blob",
|
|
479
|
+
})
|
|
480
|
+
.then(
|
|
481
|
+
(response) => this.formatResponse(response),
|
|
482
|
+
(reason) => this.formatError(reason),
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
async getUsersImports(
|
|
487
|
+
pagination: { limit: number; offset: number } = { limit: 100, offset: 0 },
|
|
488
|
+
) {
|
|
489
|
+
return this.client
|
|
490
|
+
.GET("/api/v1/user-imports/", {
|
|
491
|
+
params: {
|
|
492
|
+
query: {
|
|
493
|
+
limit: toStringOrUndefined(pagination?.limit),
|
|
494
|
+
offset: toStringOrUndefined(pagination?.offset),
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
})
|
|
498
|
+
.then(
|
|
499
|
+
(response) => this.formatResponse(response),
|
|
500
|
+
(reason) => this.formatError(reason),
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async getUsersImport(importId: string, includeUsersData?: boolean) {
|
|
505
|
+
const includeImportedData =
|
|
506
|
+
typeof includeUsersData === "undefined"
|
|
507
|
+
? undefined
|
|
508
|
+
: includeUsersData
|
|
509
|
+
? "true"
|
|
510
|
+
: "false";
|
|
511
|
+
return this.client
|
|
512
|
+
.GET("/api/v1/user-imports/{importId}", {
|
|
513
|
+
params: {
|
|
514
|
+
path: { importId },
|
|
515
|
+
query: {
|
|
516
|
+
includeImportedData,
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
})
|
|
520
|
+
.then(
|
|
521
|
+
(response) => this.formatResponse(response),
|
|
522
|
+
(reason) => this.formatError(reason),
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
async getUsersForImport(importId: string, activeOnly: boolean) {
|
|
527
|
+
return this.client
|
|
528
|
+
.GET("/api/v1/users/", {
|
|
529
|
+
params: { query: { importId, activeOnly: String(activeOnly) } },
|
|
530
|
+
})
|
|
531
|
+
.then(
|
|
532
|
+
(response) => this.formatResponse(response),
|
|
533
|
+
(reason) => this.formatError(reason),
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async getOrganisationsSettings(filter?: PaginationParams) {
|
|
538
|
+
return this.client
|
|
539
|
+
.GET("/api/v1/organisation-settings/", {
|
|
540
|
+
params: {
|
|
541
|
+
query: {
|
|
542
|
+
...preparePaginationParams(filter),
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
})
|
|
546
|
+
.then(
|
|
547
|
+
(response) => this.formatResponse(response),
|
|
548
|
+
(reason) => this.formatError(reason),
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
async getOrganisationSettings(organisationSettingId: string) {
|
|
553
|
+
return this.client
|
|
554
|
+
.GET("/api/v1/organisation-settings/{organisationSettingId}", {
|
|
555
|
+
params: { path: { organisationSettingId } },
|
|
556
|
+
})
|
|
557
|
+
.then(
|
|
558
|
+
(response) => this.formatResponse(response),
|
|
559
|
+
(reason) => this.formatError(reason),
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
async updateOrganisationSettings(
|
|
564
|
+
organisationSettingId: string,
|
|
565
|
+
body: paths["/api/v1/organisation-settings/{organisationSettingId}"]["patch"]["requestBody"]["content"]["application/json"],
|
|
566
|
+
) {
|
|
567
|
+
return this.client
|
|
568
|
+
.PATCH("/api/v1/organisation-settings/{organisationSettingId}", {
|
|
569
|
+
body,
|
|
570
|
+
params: { path: { organisationSettingId } },
|
|
571
|
+
})
|
|
572
|
+
.then(
|
|
573
|
+
(response) => this.formatResponse(response),
|
|
574
|
+
(reason) => this.formatError(reason),
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
async getMessageEvents(params: { search?: string } & PaginationParams) {
|
|
579
|
+
return this.client
|
|
580
|
+
.GET("/api/v1/message-events/", {
|
|
581
|
+
params: {
|
|
582
|
+
query: { search: params.search, ...preparePaginationParams(params) },
|
|
583
|
+
},
|
|
584
|
+
})
|
|
585
|
+
.then(
|
|
586
|
+
(response) => this.formatResponse(response),
|
|
587
|
+
(reason) => this.formatError(reason),
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
async getMessageEvent(eventId: string) {
|
|
592
|
+
return this.client
|
|
593
|
+
.GET("/api/v1/message-events/{eventId}", {
|
|
594
|
+
params: { path: { eventId } },
|
|
595
|
+
})
|
|
596
|
+
.then(
|
|
597
|
+
(response) => this.formatResponse(response),
|
|
598
|
+
(reason) => this.formatError(reason),
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async getUsers(
|
|
603
|
+
query?: paths["/api/v1/users/"]["get"]["parameters"]["query"],
|
|
604
|
+
) {
|
|
605
|
+
return this.client
|
|
606
|
+
.GET("/api/v1/users/", {
|
|
607
|
+
params: {
|
|
608
|
+
query: { ...query, ...preparePaginationParams(query) },
|
|
609
|
+
},
|
|
610
|
+
})
|
|
611
|
+
.then(
|
|
612
|
+
(response) => this.formatResponse(response),
|
|
613
|
+
(reason) => this.formatError(reason),
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
async getUser(
|
|
618
|
+
userId: paths["/api/v1/users/{userId}"]["get"]["parameters"]["path"]["userId"],
|
|
619
|
+
activeOnly: boolean,
|
|
620
|
+
) {
|
|
621
|
+
return this.client
|
|
622
|
+
.GET("/api/v1/users/{userId}", {
|
|
623
|
+
params: {
|
|
624
|
+
path: {
|
|
625
|
+
userId,
|
|
626
|
+
},
|
|
627
|
+
query: {
|
|
628
|
+
activeOnly: toStringOrUndefined(activeOnly),
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
})
|
|
632
|
+
.then(
|
|
633
|
+
(response) => this.formatResponse(response),
|
|
634
|
+
(reason) => this.formatError(reason),
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
async seeMessage(messageId: string) {
|
|
639
|
+
return this.client
|
|
640
|
+
.PUT("/api/v1/message-actions/{messageId}", {
|
|
641
|
+
params: {
|
|
642
|
+
path: {
|
|
643
|
+
messageId,
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
body: {
|
|
647
|
+
messageId,
|
|
648
|
+
isSeen: true,
|
|
649
|
+
},
|
|
650
|
+
})
|
|
651
|
+
.then(
|
|
652
|
+
(response) => this.formatResponse(response),
|
|
653
|
+
(reason) => this.formatError(reason),
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
async unseeMessage(messageId: string) {
|
|
658
|
+
return this.client
|
|
659
|
+
.PUT("/api/v1/message-actions/{messageId}", {
|
|
660
|
+
params: {
|
|
661
|
+
path: {
|
|
662
|
+
messageId,
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
body: {
|
|
666
|
+
messageId,
|
|
667
|
+
isSeen: false,
|
|
668
|
+
},
|
|
669
|
+
})
|
|
670
|
+
.then(
|
|
671
|
+
(response) => this.formatResponse(response),
|
|
672
|
+
(reason) => this.formatError(reason),
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
newInterpolator(interpolations: Record<string, string>) {
|
|
677
|
+
return function replacer(acc: string, key: string) {
|
|
678
|
+
return acc.replaceAll(`{{${key}}}`, interpolations[key]);
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export default Messaging;
|