@koloseum/utils 0.1.14 → 0.1.15

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 CHANGED
@@ -1,11 +1,10 @@
1
1
  import type { Database } from "@koloseum/types/database";
2
- import type { CustomError, Microservice, MicroserviceGroup, MicroserviceObject, UserWithAppMetadata } from "@koloseum/types/general";
2
+ import type { CustomError, Microservice, MicroserviceGroup, MicroserviceObject } from "@koloseum/types/general";
3
3
  import type { PronounsCheckboxes, SocialMediaPlatform } from "@koloseum/types/public-auth";
4
4
  import type { Page } from "@sveltejs/kit";
5
5
  import type { SupabaseClient, PostgrestError } from "@supabase/supabase-js";
6
- import type { SubscriberResponseDto } from "@novu/api/models/components/subscriberresponsedto.js";
6
+ import type { IOptions } from "@suprsend/web-components/dist/types/interface.d.ts";
7
7
  import type { MobilePhoneLocale } from "validator";
8
- import { Novu } from "@novu/api";
9
8
  export declare const Status: {
10
9
  /**
11
10
  * A generic error message.
@@ -74,12 +73,12 @@ export declare const Utility: {
74
73
  */
75
74
  getAge: (dateOfBirth: string) => number;
76
75
  /**
77
- * Get a Novu subscriber.
78
- * @param novu - The Novu client.
79
- * @param user - The user object.
80
- * @returns The subscriber object or `null` if no Novu client or user is provided.
76
+ * Generate a SuprSend configuration object for a user.
77
+ * @param {string} userId - The user ID to generate the configuration for.
78
+ * @param {string} publicApiKey - The public API key to use for SuprSend.
79
+ * @returns The SuprSend configuration object.
81
80
  */
82
- getNovuSubscriber: (novu: Novu, user: UserWithAppMetadata | null) => Promise<SubscriberResponseDto | null>;
81
+ getSuprSendConfig: (userId: string, publicApiKey: string) => IOptions;
83
82
  /**
84
83
  * Handles the click event for pronouns checkboxes.
85
84
  * @param {MouseEvent} e - The click event
package/dist/utils.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { error as svelteError } from "@sveltejs/kit";
2
2
  import { FunctionsFetchError, FunctionsHttpError, FunctionsRelayError } from "@supabase/supabase-js";
3
- import { ErrorDto } from "@novu/api/models/errors/errordto.js";
4
3
  import sanitize from "sanitize-html";
5
4
  import validator from "validator";
6
5
  /* Helper functions */
@@ -181,52 +180,148 @@ export const Utility = {
181
180
  return monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate()) ? --age : age;
182
181
  },
183
182
  /**
184
- * Get a Novu subscriber.
185
- * @param novu - The Novu client.
186
- * @param user - The user object.
187
- * @returns The subscriber object or `null` if no Novu client or user is provided.
183
+ * Generate a SuprSend configuration object for a user.
184
+ * @param {string} userId - The user ID to generate the configuration for.
185
+ * @param {string} publicApiKey - The public API key to use for SuprSend.
186
+ * @returns The SuprSend configuration object.
188
187
  */
189
- getNovuSubscriber: async (novu, user) => {
190
- // Initialise subscriber as null
191
- let subscriber = null;
192
- // Return null if no Novu client or user is provided
193
- if (!novu || !user)
194
- return subscriber;
195
- // Return null if no person data is provided
196
- if (!user.app_metadata.person_data)
197
- return subscriber;
198
- try {
199
- // Get subscriber
200
- ({ result: subscriber } = await novu.subscribers.retrieve(user.id));
201
- }
202
- catch (error) {
203
- // Create subscriber if not found
204
- if (error instanceof ErrorDto && error.statusCode === 404 && user.app_metadata.person_data) {
205
- // Get person data from user metadata
206
- const { first_name: firstName, last_name: lastName, pseudonym } = user.app_metadata.person_data;
207
- // Create subscriber
208
- try {
209
- ({ result: subscriber } = await novu.subscribers.create({
210
- subscriberId: user.id,
211
- firstName,
212
- lastName,
213
- phone: user.phone,
214
- timezone: "Africa/Nairobi",
215
- locale: "en_KE",
216
- data: { pseudonym }
217
- }));
188
+ getSuprSendConfig: (userId, publicApiKey) => ({
189
+ distinctId: userId,
190
+ publicApiKey,
191
+ inbox: {
192
+ stores: [
193
+ { storeId: "all", label: "Inbox", query: { archived: false } },
194
+ { storeId: "archived", label: "Archived", query: { archived: true } }
195
+ ],
196
+ theme: {
197
+ bell: {
198
+ color: "var(--color-accent)"
199
+ },
200
+ badge: {
201
+ backgroundColor: "var(--color-primary)",
202
+ color: "var(--color-primary-content)"
203
+ },
204
+ header: {
205
+ container: {
206
+ backgroundColor: "var(--color-base-100)",
207
+ borderColor: "var(--color-base-200)"
208
+ },
209
+ headerText: {
210
+ color: "var(--color-neutral)"
211
+ },
212
+ markAllReadText: {
213
+ color: "var(--color-accent)"
214
+ }
215
+ },
216
+ tabs: {
217
+ color: "var(--color-primary)",
218
+ unselectedColor: "var(--color-accent)",
219
+ bottomColor: "var(--color-primary)",
220
+ badgeColor: "var(--color-base-200)",
221
+ badgeText: "var(--color-accent)"
222
+ },
223
+ notificationsContainer: {
224
+ container: {
225
+ backgroundColor: "var(--color-base-100)",
226
+ borderColor: "var(--color-base-200)",
227
+ height: "75vh",
228
+ marginTop: "0.75rem"
229
+ },
230
+ noNotificationsText: {
231
+ color: "var(--color-warning)"
232
+ },
233
+ noNotificationsSubtext: {
234
+ color: "var(--color-neutral)"
235
+ },
236
+ loader: {
237
+ color: "var(--color-primary)"
238
+ }
239
+ },
240
+ notification: {
241
+ container: {
242
+ borderColor: "var(--color-base-200)",
243
+ readBackgroundColor: "var(--color-base-100)",
244
+ unreadBackgroundColor: "var(--color-base-150)",
245
+ hoverBackgroundColor: "var(--color-base-200)"
246
+ },
247
+ headerText: {
248
+ color: "var(--color-secondary)"
249
+ },
250
+ bodyText: {
251
+ color: "var(--color-neutral)",
252
+ linkColor: "var(--color-secondary)"
253
+ },
254
+ unseenDot: {
255
+ backgroundColor: "var(--color-warning)"
256
+ },
257
+ createdOnText: {
258
+ color: "var(--color-accent)"
259
+ },
260
+ subtext: {
261
+ color: "var(--color-neutral)"
262
+ },
263
+ expiresText: {
264
+ color: "var(--color-warning)",
265
+ expiringBackgroundColor: "var(--color-warning)",
266
+ expiringColor: "var(--color-neutral)"
267
+ },
268
+ actions: [
269
+ {
270
+ text: {
271
+ color: "var(--color-primary-content)"
272
+ },
273
+ container: {
274
+ backgroundColor: "var(--color-primary)",
275
+ hoverBackgroundColor: "var(--color-secondary)",
276
+ border: "unset"
277
+ }
278
+ },
279
+ {
280
+ text: {
281
+ color: "var(--color-primary-content)"
282
+ },
283
+ container: {
284
+ backgroundColor: "var(--color-primary)",
285
+ hoverBackgroundColor: "var(--color-secondary)",
286
+ border: "unset"
287
+ }
288
+ }
289
+ ],
290
+ actionsMenuIcon: {
291
+ hoverBackgroundColor: "var(--color-base-200)",
292
+ color: "var(--color-neutral)"
293
+ },
294
+ actionsMenu: {
295
+ backgroundColor: "var(--color-base-100)",
296
+ borderColor: "var(--color-base-200)"
297
+ },
298
+ actionsMenuItem: {
299
+ hoverBackgroundColor: "var(--color-base-200)"
300
+ },
301
+ actionsMenuItemIcon: {
302
+ color: "var(--color-accent)"
303
+ },
304
+ actionsMenuItemText: {
305
+ color: "var(--color-neutral)"
306
+ }
218
307
  }
219
- catch (error) {
220
- console.error(error);
308
+ }
309
+ },
310
+ toast: {
311
+ theme: {
312
+ container: {
313
+ backgroundColor: "var(--color-base-100)",
314
+ borderColor: "var(--color-base-200)"
315
+ },
316
+ headerText: {
317
+ color: "var(--color-primary)"
318
+ },
319
+ bodyText: {
320
+ color: "var(--color-neutral)"
221
321
  }
222
322
  }
223
- // Otherwise, log error
224
- else
225
- console.error(error);
226
323
  }
227
- // Return subscriber
228
- return subscriber;
229
- },
324
+ }),
230
325
  /**
231
326
  * Handles the click event for pronouns checkboxes.
232
327
  * @param {MouseEvent} e - The click event
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koloseum/utils",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "author": "Koloseum Technologies Limited",
5
5
  "type": "module",
6
6
  "description": "Utility logic for use across Koloseum web apps (TypeScript)",
@@ -29,7 +29,6 @@
29
29
  "test": "vitest --run"
30
30
  },
31
31
  "dependencies": {
32
- "@novu/api": "^0.6.1",
33
32
  "@supabase/supabase-js": "^2.48.1",
34
33
  "@sveltejs/kit": "^2.17.1",
35
34
  "sanitize-html": "^2.14.0",
@@ -38,6 +37,7 @@
38
37
  "devDependencies": {
39
38
  "@koloseum/types": "^0.1.12",
40
39
  "@playwright/test": "^1.50.1",
40
+ "@suprsend/web-components": "^0.2.1",
41
41
  "@types/sanitize-html": "^2.13.0",
42
42
  "@types/validator": "^13.12.2",
43
43
  "prettier": "^3.5.1",