@koloseum/utils 0.1.10 → 0.1.12
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/dist/utils.d.ts +29 -1
- package/dist/utils.js +233 -0
- package/package.json +3 -2
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { CustomError } from "@koloseum/types/general";
|
|
1
|
+
import type { CustomError, Microservice, MicroserviceGroup, MicroserviceObject, UserWithAppMetadata } from "@koloseum/types/general";
|
|
2
2
|
import type { PronounsCheckboxes, SocialMediaPlatform } from "@koloseum/types/public-auth";
|
|
3
|
+
import type { SubscriberResponseDto } from "@novu/api/models/components/subscriberresponsedto.js";
|
|
3
4
|
import type { PostgrestError } from "@supabase/supabase-js";
|
|
5
|
+
import type { Page } from "@sveltejs/kit";
|
|
4
6
|
import type { MobilePhoneLocale } from "validator";
|
|
7
|
+
import { Novu } from "@novu/api";
|
|
5
8
|
export declare const Status: {
|
|
6
9
|
/**
|
|
7
10
|
* A generic error message.
|
|
@@ -55,6 +58,13 @@ export declare const Utility: {
|
|
|
55
58
|
* @returns The age in years, or `NaN` if the input is invalid
|
|
56
59
|
*/
|
|
57
60
|
getAge: (dateOfBirth: string) => number;
|
|
61
|
+
/**
|
|
62
|
+
* Get a Novu subscriber.
|
|
63
|
+
* @param novu - The Novu client.
|
|
64
|
+
* @param user - The user object.
|
|
65
|
+
* @returns The subscriber object or `null` if no Novu client or user is provided.
|
|
66
|
+
*/
|
|
67
|
+
getNovuSubscriber: (novu: Novu, user: UserWithAppMetadata | null) => Promise<SubscriberResponseDto | null>;
|
|
58
68
|
/**
|
|
59
69
|
* Handles the click event for pronouns checkboxes.
|
|
60
70
|
* @param {MouseEvent} e - The click event
|
|
@@ -73,10 +83,28 @@ export declare const Utility: {
|
|
|
73
83
|
* - begins with "KL" followed by 7 digits
|
|
74
84
|
*/
|
|
75
85
|
loungeIdRegex: RegExp;
|
|
86
|
+
/**
|
|
87
|
+
* A reference of microservices available on the platform, represented as an object with each user group (i.e. `public`, `players`, `lounges`, and `backroom`) having its own array of microservices. Each microservice in a list is an object with the following properties:
|
|
88
|
+
* - `name`: The name of the microservice.
|
|
89
|
+
* - `description`: A description of the microservice.
|
|
90
|
+
* - `slug`: The slug of the microservice.
|
|
91
|
+
* - `features`: An array of features that the microservice has.
|
|
92
|
+
* - `roles`: An array of roles attached to the microservice.
|
|
93
|
+
*/
|
|
94
|
+
microservices: { [key in MicroserviceGroup]: MicroserviceObject<key>[]; };
|
|
76
95
|
/**
|
|
77
96
|
* The minimum birth date (from today's date) for a user who is a minor, i.e. `YYYY-MM-DD`
|
|
78
97
|
*/
|
|
79
98
|
minimumMinorBirthDate: string;
|
|
99
|
+
/**
|
|
100
|
+
* Check if a page is active based on the slug and microservice.
|
|
101
|
+
* @param page - The current page object.
|
|
102
|
+
* @param slug - The slug of the page to check.
|
|
103
|
+
* @param microservice - The microservice to check against.
|
|
104
|
+
* @param base - The base path of the application; defaults to an empty string.
|
|
105
|
+
* @returns `true` if the page is active, `false` otherwise.
|
|
106
|
+
*/
|
|
107
|
+
pageIsActive: (page: Page, slug: string, microservice?: Microservice<MicroserviceGroup>, base?: string) => boolean;
|
|
80
108
|
/**
|
|
81
109
|
* Parses a `CustomError` object within a page/layout server load function and returns an error to be thrown.
|
|
82
110
|
* @param {CustomError} error - The error object
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { error as svelteError } from "@sveltejs/kit";
|
|
2
|
+
import { ErrorDto } from "@novu/api/models/errors/errordto.js";
|
|
2
3
|
import sanitize from "sanitize-html";
|
|
3
4
|
import validator from "validator";
|
|
4
5
|
/* Helper functions */
|
|
@@ -108,6 +109,48 @@ export const Utility = {
|
|
|
108
109
|
const monthDiff = currentDate.getMonth() - birthDate.getMonth();
|
|
109
110
|
return monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate()) ? --age : age;
|
|
110
111
|
},
|
|
112
|
+
/**
|
|
113
|
+
* Get a Novu subscriber.
|
|
114
|
+
* @param novu - The Novu client.
|
|
115
|
+
* @param user - The user object.
|
|
116
|
+
* @returns The subscriber object or `null` if no Novu client or user is provided.
|
|
117
|
+
*/
|
|
118
|
+
getNovuSubscriber: async (novu, user) => {
|
|
119
|
+
// Initialise subscriber as null
|
|
120
|
+
let subscriber = null;
|
|
121
|
+
// Return null if no Novu client or user is provided
|
|
122
|
+
if (!novu || !user)
|
|
123
|
+
return subscriber;
|
|
124
|
+
// Return null if no person data is provided
|
|
125
|
+
if (!user.app_metadata.person_data)
|
|
126
|
+
return subscriber;
|
|
127
|
+
try {
|
|
128
|
+
// Get subscriber
|
|
129
|
+
({ result: subscriber } = await novu.subscribers.retrieve(user.id));
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
// Create subscriber if not found
|
|
133
|
+
if (error instanceof ErrorDto && error.statusCode === 404 && user.app_metadata.person_data) {
|
|
134
|
+
// Get person data from user metadata
|
|
135
|
+
const { first_name: firstName, last_name: lastName, pseudonym } = user.app_metadata.person_data;
|
|
136
|
+
// Create subscriber
|
|
137
|
+
({ result: subscriber } = await novu.subscribers.create({
|
|
138
|
+
subscriberId: user.id,
|
|
139
|
+
firstName,
|
|
140
|
+
lastName,
|
|
141
|
+
phone: user.phone,
|
|
142
|
+
timezone: "Africa/Nairobi",
|
|
143
|
+
locale: "en_KE",
|
|
144
|
+
data: { pseudonym }
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
// Otherwise, log error
|
|
148
|
+
else
|
|
149
|
+
console.error(error);
|
|
150
|
+
}
|
|
151
|
+
// Return subscriber
|
|
152
|
+
return subscriber;
|
|
153
|
+
},
|
|
111
154
|
/**
|
|
112
155
|
* Handles the click event for pronouns checkboxes.
|
|
113
156
|
* @param {MouseEvent} e - The click event
|
|
@@ -170,6 +213,187 @@ export const Utility = {
|
|
|
170
213
|
* - begins with "KL" followed by 7 digits
|
|
171
214
|
*/
|
|
172
215
|
loungeIdRegex: /^KL\d{7}$/,
|
|
216
|
+
/**
|
|
217
|
+
* A reference of microservices available on the platform, represented as an object with each user group (i.e. `public`, `players`, `lounges`, and `backroom`) having its own array of microservices. Each microservice in a list is an object with the following properties:
|
|
218
|
+
* - `name`: The name of the microservice.
|
|
219
|
+
* - `description`: A description of the microservice.
|
|
220
|
+
* - `slug`: The slug of the microservice.
|
|
221
|
+
* - `features`: An array of features that the microservice has.
|
|
222
|
+
* - `roles`: An array of roles attached to the microservice.
|
|
223
|
+
*/
|
|
224
|
+
microservices: {
|
|
225
|
+
backroom: [
|
|
226
|
+
{
|
|
227
|
+
name: "Compliance",
|
|
228
|
+
description: "Management of compliance and regulatory requirements for Players and Lounges.",
|
|
229
|
+
slug: "compliance",
|
|
230
|
+
features: [
|
|
231
|
+
{
|
|
232
|
+
name: "Players",
|
|
233
|
+
description: "Manage Player data.",
|
|
234
|
+
slug: "players"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: "Lounges",
|
|
238
|
+
description: "Manage Lounge data.",
|
|
239
|
+
slug: "lounges"
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
roles: [
|
|
243
|
+
{
|
|
244
|
+
name: "Compliance",
|
|
245
|
+
slug: "compliance",
|
|
246
|
+
root: true
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "Players",
|
|
250
|
+
slug: "players",
|
|
251
|
+
featureSlugs: ["players"]
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: "Lounges",
|
|
255
|
+
slug: "lounges",
|
|
256
|
+
featureSlugs: ["lounges"]
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "Competitions",
|
|
262
|
+
description: "Management of competitions data and live events across Markets.",
|
|
263
|
+
slug: "competitions",
|
|
264
|
+
features: [
|
|
265
|
+
{
|
|
266
|
+
name: "Ma Esto",
|
|
267
|
+
description: "Manage football esports data for Ma Esto.",
|
|
268
|
+
slug: "fbl"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "Savanna FGC",
|
|
272
|
+
description: "Manage fighting games esports data for Savanna FGC.",
|
|
273
|
+
slug: "fgc"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: "Hit List",
|
|
277
|
+
description: "Manage battle royale esports data for Hit List.",
|
|
278
|
+
slug: "bryl"
|
|
279
|
+
}
|
|
280
|
+
],
|
|
281
|
+
roles: [
|
|
282
|
+
{
|
|
283
|
+
name: "Competitions",
|
|
284
|
+
slug: "competitions",
|
|
285
|
+
root: true
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "Ma Esto",
|
|
289
|
+
slug: "fbl",
|
|
290
|
+
featureSlugs: ["fbl"]
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "Savanna FGC",
|
|
294
|
+
slug: "fgc",
|
|
295
|
+
featureSlugs: ["fgc"]
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: "Hit List",
|
|
299
|
+
slug: "bryl",
|
|
300
|
+
featureSlugs: ["bryl"]
|
|
301
|
+
}
|
|
302
|
+
]
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: "KLSM",
|
|
306
|
+
description: "Management of store products and tracking of orders and payments.",
|
|
307
|
+
slug: "commerce",
|
|
308
|
+
features: [
|
|
309
|
+
{
|
|
310
|
+
name: "Sections",
|
|
311
|
+
description: "Manage store sections.",
|
|
312
|
+
slug: "sections"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "Products",
|
|
316
|
+
description: "Manage store products.",
|
|
317
|
+
slug: "products"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "Bundles",
|
|
321
|
+
description: "Manage store bundles.",
|
|
322
|
+
slug: "bundles"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: "Inventory",
|
|
326
|
+
description: "Manage store inventory.",
|
|
327
|
+
slug: "inventory"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
name: "Orders",
|
|
331
|
+
description: "Manage store orders.",
|
|
332
|
+
slug: "orders"
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
roles: [
|
|
336
|
+
{
|
|
337
|
+
name: "Commerce",
|
|
338
|
+
slug: "commerce",
|
|
339
|
+
root: true
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: "Storefront",
|
|
343
|
+
slug: "storefront",
|
|
344
|
+
featureSlugs: ["sections", "products", "bundles"]
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "Warehouse",
|
|
348
|
+
slug: "warehouse",
|
|
349
|
+
featureSlugs: ["inventory", "orders"]
|
|
350
|
+
}
|
|
351
|
+
]
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "Staff",
|
|
355
|
+
description: "Management of staff authorisation.",
|
|
356
|
+
slug: "staff",
|
|
357
|
+
features: [
|
|
358
|
+
{
|
|
359
|
+
name: "Roles",
|
|
360
|
+
description: "Review and manage Backroom roles.",
|
|
361
|
+
slug: "roles"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "Users",
|
|
365
|
+
description: "Review and manage Backroom users.",
|
|
366
|
+
slug: "users"
|
|
367
|
+
}
|
|
368
|
+
],
|
|
369
|
+
roles: [
|
|
370
|
+
{
|
|
371
|
+
name: "Human Resources",
|
|
372
|
+
slug: "hr",
|
|
373
|
+
root: true
|
|
374
|
+
}
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: "Account",
|
|
379
|
+
description: "Review of access and notifications.",
|
|
380
|
+
slug: "account",
|
|
381
|
+
features: [
|
|
382
|
+
{
|
|
383
|
+
name: "Access",
|
|
384
|
+
description: "Review access to Backroom microservices.",
|
|
385
|
+
slug: "access"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: "Notifications",
|
|
389
|
+
description: "Review and manage Backroom notifications.",
|
|
390
|
+
slug: "notifications"
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
roles: null
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
},
|
|
173
397
|
/**
|
|
174
398
|
* The minimum birth date (from today's date) for a user who is a minor, i.e. `YYYY-MM-DD`
|
|
175
399
|
*/
|
|
@@ -181,6 +405,15 @@ export const Utility = {
|
|
|
181
405
|
tomorrow.setFullYear(tomorrow18YearsAgo);
|
|
182
406
|
return tomorrow.toISOString().split("T")[0];
|
|
183
407
|
})(),
|
|
408
|
+
/**
|
|
409
|
+
* Check if a page is active based on the slug and microservice.
|
|
410
|
+
* @param page - The current page object.
|
|
411
|
+
* @param slug - The slug of the page to check.
|
|
412
|
+
* @param microservice - The microservice to check against.
|
|
413
|
+
* @param base - The base path of the application; defaults to an empty string.
|
|
414
|
+
* @returns `true` if the page is active, `false` otherwise.
|
|
415
|
+
*/
|
|
416
|
+
pageIsActive: (page, slug, microservice, base = "") => slug === microservice || page.url.pathname.startsWith(`${base === "." ? "" : base}/${slug}`),
|
|
184
417
|
/**
|
|
185
418
|
* Parses a `CustomError` object within a page/layout server load function and returns an error to be thrown.
|
|
186
419
|
* @param {CustomError} error - The error object
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koloseum/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"author": "Koloseum Technologies Limited",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Utility logic for use across Koloseum web apps (TypeScript)",
|
|
@@ -29,13 +29,14 @@
|
|
|
29
29
|
"test": "vitest --run"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@novu/api": "^0.6.1",
|
|
32
33
|
"@supabase/supabase-js": "^2.48.1",
|
|
33
34
|
"@sveltejs/kit": "^2.17.1",
|
|
34
35
|
"sanitize-html": "^2.14.0",
|
|
35
36
|
"validator": "^13.12.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@koloseum/types": "^0.1.
|
|
39
|
+
"@koloseum/types": "^0.1.12",
|
|
39
40
|
"@playwright/test": "^1.50.1",
|
|
40
41
|
"@types/sanitize-html": "^2.13.0",
|
|
41
42
|
"@types/validator": "^13.12.2",
|