@koloseum/utils 0.1.15 → 0.1.16
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 +17 -0
- package/dist/utils.js +39 -1
- package/package.json +2 -1
package/dist/utils.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { CustomError, Microservice, MicroserviceGroup, MicroserviceObject }
|
|
|
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 { suprsend } from "@suprsend/node-sdk";
|
|
6
7
|
import type { IOptions } from "@suprsend/web-components/dist/types/interface.d.ts";
|
|
7
8
|
import type { MobilePhoneLocale } from "validator";
|
|
8
9
|
export declare const Status: {
|
|
@@ -173,4 +174,20 @@ export declare const Utility: {
|
|
|
173
174
|
* @returns `true` if the handle is valid; `false` otherwise
|
|
174
175
|
*/
|
|
175
176
|
validateSocialMediaHandle: (handle: string) => boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Validates a SuprSend subscriber. If the subscriber does not exist, it will be created with the provided person data.
|
|
179
|
+
* @param {suprsend.Suprsend} suprSend - The SuprSend instance.
|
|
180
|
+
* @param {string} userId - The user ID.
|
|
181
|
+
* @param {Object} personData - The person data; required if the subscriber does not exist.
|
|
182
|
+
* @returns {Promise<{ error?: CustomError; success?: true }>} A promise that resolves to an object with an error if the subscriber validation fails, or indicating success otherwise.
|
|
183
|
+
*/
|
|
184
|
+
validateSuprSendSubscriber: (suprSend: suprsend.Suprsend, userId: string, personData?: {
|
|
185
|
+
firstName: string;
|
|
186
|
+
lastName: string;
|
|
187
|
+
phone: string;
|
|
188
|
+
pseudonym?: string;
|
|
189
|
+
}) => Promise<{
|
|
190
|
+
error?: CustomError;
|
|
191
|
+
success?: true;
|
|
192
|
+
}>;
|
|
176
193
|
};
|
package/dist/utils.js
CHANGED
|
@@ -690,5 +690,43 @@ export const Utility = {
|
|
|
690
690
|
*/
|
|
691
691
|
validateSocialMediaHandle: (handle) => !isURL(handle, { require_protocol: false }) &&
|
|
692
692
|
!handle.startsWith("@") &&
|
|
693
|
-
Boolean(handle.match(Utility.socialMediaHandleRegex))
|
|
693
|
+
Boolean(handle.match(Utility.socialMediaHandleRegex)),
|
|
694
|
+
/**
|
|
695
|
+
* Validates a SuprSend subscriber. If the subscriber does not exist, it will be created with the provided person data.
|
|
696
|
+
* @param {suprsend.Suprsend} suprSend - The SuprSend instance.
|
|
697
|
+
* @param {string} userId - The user ID.
|
|
698
|
+
* @param {Object} personData - The person data; required if the subscriber does not exist.
|
|
699
|
+
* @returns {Promise<{ error?: CustomError; success?: true }>} A promise that resolves to an object with an error if the subscriber validation fails, or indicating success otherwise.
|
|
700
|
+
*/
|
|
701
|
+
validateSuprSendSubscriber: async (suprSend, userId, personData) => {
|
|
702
|
+
// Check if subscriber exists
|
|
703
|
+
try {
|
|
704
|
+
await suprSend.users.get(userId);
|
|
705
|
+
}
|
|
706
|
+
catch (_err) {
|
|
707
|
+
// If person data is not provided, return an error
|
|
708
|
+
if (!personData)
|
|
709
|
+
return { error: Utility.customError(400, "Person data is required to create a SuprSend subscriber.") };
|
|
710
|
+
// Destructure person data
|
|
711
|
+
const { firstName, lastName, phone, pseudonym } = personData;
|
|
712
|
+
// Create subscriber
|
|
713
|
+
const subscriber = suprSend.user.get_instance(userId);
|
|
714
|
+
if (!subscriber)
|
|
715
|
+
return { error: Utility.customError(500, Status.ERROR) };
|
|
716
|
+
// Set subscriber details
|
|
717
|
+
subscriber.set_preferred_language("en");
|
|
718
|
+
subscriber.set_timezone("Africa/Nairobi");
|
|
719
|
+
subscriber.set("firstName", firstName);
|
|
720
|
+
subscriber.set("lastName", lastName);
|
|
721
|
+
subscriber.set("phone", `+${phone}`);
|
|
722
|
+
if (pseudonym)
|
|
723
|
+
subscriber.set("pseudonym", pseudonym);
|
|
724
|
+
// Save subscriber
|
|
725
|
+
const response = await subscriber.save();
|
|
726
|
+
if (!response.success)
|
|
727
|
+
return { error: Utility.customError(500, Status.ERROR) };
|
|
728
|
+
}
|
|
729
|
+
// Return success
|
|
730
|
+
return { success: true };
|
|
731
|
+
}
|
|
694
732
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koloseum/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"author": "Koloseum Technologies Limited",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Utility logic for use across Koloseum web apps (TypeScript)",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@koloseum/types": "^0.1.12",
|
|
39
39
|
"@playwright/test": "^1.50.1",
|
|
40
|
+
"@suprsend/node-sdk": "^1.13.0",
|
|
40
41
|
"@suprsend/web-components": "^0.2.1",
|
|
41
42
|
"@types/sanitize-html": "^2.13.0",
|
|
42
43
|
"@types/validator": "^13.12.2",
|