@koloseum/utils 0.2.23 → 0.2.25
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.js +57 -33
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -107,35 +107,38 @@ export const Utility = {
|
|
|
107
107
|
// Define context
|
|
108
108
|
const context = {};
|
|
109
109
|
// Define error code and message
|
|
110
|
-
const code = Number(error.context
|
|
111
|
-
let message = error.context
|
|
112
|
-
? Status.ERROR
|
|
113
|
-
: error.context.statusText || Status.ERROR;
|
|
110
|
+
const code = Number(error.context?.status) || 500;
|
|
111
|
+
let message = error.context?.statusText || Status.ERROR;
|
|
114
112
|
// Handle HTTP errors
|
|
115
113
|
if (error instanceof FunctionsHttpError) {
|
|
116
|
-
// Get error data
|
|
117
114
|
try {
|
|
118
|
-
// Get content type header
|
|
119
|
-
const contentType = error.context
|
|
115
|
+
// Get content type header safely
|
|
116
|
+
const contentType = error.context?.headers?.get("content-type") || "";
|
|
120
117
|
// If content type is JSON, get error data
|
|
121
118
|
if (contentType.includes("application/json")) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
try {
|
|
120
|
+
const errorData = await error.context.json();
|
|
121
|
+
message = errorData.message || message;
|
|
122
|
+
// Assign attempt ID to context if present
|
|
123
|
+
if (path.includes("verify-id") && errorData.attemptId)
|
|
124
|
+
context.attemptId = errorData.attemptId;
|
|
125
|
+
}
|
|
126
|
+
catch (jsonError) {
|
|
127
|
+
console.error("Failed to parse JSON error response:", jsonError);
|
|
128
|
+
}
|
|
126
129
|
}
|
|
127
130
|
// If content type is plain text, get error message
|
|
128
|
-
else if (contentType.includes("text/plain"))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
else if (contentType.includes("text/plain")) {
|
|
132
|
+
try {
|
|
133
|
+
message = await error.context.text();
|
|
134
|
+
}
|
|
135
|
+
catch (textError) {
|
|
136
|
+
console.error("Failed to parse text error response:", textError);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
136
139
|
}
|
|
137
|
-
catch {
|
|
138
|
-
|
|
140
|
+
catch (parseError) {
|
|
141
|
+
console.error("Failed to parse error response:", parseError);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
// Handle relay and fetch errors
|
|
@@ -147,7 +150,8 @@ export const Utility = {
|
|
|
147
150
|
// Return response
|
|
148
151
|
return { code: 200, data };
|
|
149
152
|
}
|
|
150
|
-
catch {
|
|
153
|
+
catch (unexpectedError) {
|
|
154
|
+
console.error("Unexpected error:", unexpectedError);
|
|
151
155
|
return { code: 500, error: Status.ERROR };
|
|
152
156
|
}
|
|
153
157
|
},
|
|
@@ -860,7 +864,7 @@ export const Utility = {
|
|
|
860
864
|
.rpc("authorise", { requested_permission: requestedPermission });
|
|
861
865
|
if (isAuthorisedError)
|
|
862
866
|
return Utility.parsePostgrestError(isAuthorisedError);
|
|
863
|
-
//
|
|
867
|
+
// Assign result of authorisation check
|
|
864
868
|
isAuthorised = data;
|
|
865
869
|
}
|
|
866
870
|
// Validate SuprSend subscriber
|
|
@@ -869,7 +873,7 @@ export const Utility = {
|
|
|
869
873
|
const { first_name: firstName, last_name: lastName, pseudonym } = user.app_metadata.person_data;
|
|
870
874
|
personData = { firstName, lastName, phone: user.phone, pseudonym };
|
|
871
875
|
}
|
|
872
|
-
const { code, error: validationError } = await Utility.callEdgeFunction(false, supabase, `suprsend/validate-subscriber?user-id=${user.id}`, { method: "POST", body: personData });
|
|
876
|
+
const { code, error: validationError } = await Utility.callEdgeFunction(false, supabase, `suprsend/validate-subscriber?user-id=${user.id}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(personData) });
|
|
873
877
|
if (validationError)
|
|
874
878
|
return { error: Utility.customError(code, validationError) };
|
|
875
879
|
// Send welcome notification if needed
|
|
@@ -1267,15 +1271,35 @@ export const Utility = {
|
|
|
1267
1271
|
description: "Review Player account settings and preferences.",
|
|
1268
1272
|
slug: "account",
|
|
1269
1273
|
features: [
|
|
1274
|
+
{
|
|
1275
|
+
name: "Personal",
|
|
1276
|
+
description: "Review and manage your personal information.",
|
|
1277
|
+
slug: "personal"
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
name: "Gaming & Socials",
|
|
1281
|
+
description: "Review and manage your gaming and social media information.",
|
|
1282
|
+
slug: "gaming-socials"
|
|
1283
|
+
},
|
|
1270
1284
|
{
|
|
1271
1285
|
name: "Notifications",
|
|
1272
|
-
description: "Review and manage notification preferences.",
|
|
1286
|
+
description: "Review and manage your notification preferences.",
|
|
1273
1287
|
slug: "notifications"
|
|
1274
1288
|
},
|
|
1275
1289
|
{
|
|
1276
|
-
name: "
|
|
1277
|
-
description: "Review
|
|
1278
|
-
slug: "
|
|
1290
|
+
name: "Security",
|
|
1291
|
+
description: "Review and manage your security preferences.",
|
|
1292
|
+
slug: "security"
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
name: "Lounges",
|
|
1296
|
+
description: "Review your access to Lounges microservices.",
|
|
1297
|
+
slug: "lounges"
|
|
1298
|
+
},
|
|
1299
|
+
{
|
|
1300
|
+
name: "Backroom",
|
|
1301
|
+
description: "Review your access to Backroom microservices.",
|
|
1302
|
+
slug: "backroom"
|
|
1279
1303
|
}
|
|
1280
1304
|
],
|
|
1281
1305
|
roles: null
|
|
@@ -1349,13 +1373,13 @@ export const Utility = {
|
|
|
1349
1373
|
if (!interval)
|
|
1350
1374
|
return null;
|
|
1351
1375
|
// Parse interval and return in the specified format
|
|
1352
|
-
const
|
|
1376
|
+
const { toPostgres, toISOString, toISOStringShort } = parsePgInterval(interval);
|
|
1353
1377
|
if (type === "postgres")
|
|
1354
|
-
return
|
|
1378
|
+
return toPostgres();
|
|
1355
1379
|
if (type === "iso")
|
|
1356
|
-
return
|
|
1380
|
+
return toISOString();
|
|
1357
1381
|
if (type === "iso-short")
|
|
1358
|
-
return
|
|
1382
|
+
return toISOStringShort();
|
|
1359
1383
|
// Return null if type is invalid
|
|
1360
1384
|
return null;
|
|
1361
1385
|
},
|
|
@@ -1491,7 +1515,7 @@ export const Utility = {
|
|
|
1491
1515
|
]
|
|
1492
1516
|
};
|
|
1493
1517
|
// Send welcome notification
|
|
1494
|
-
const { code, error: workflowError } = await Utility.callEdgeFunction(false, supabase, `suprsend/trigger-workflow?user-id=${user.id}`, { method: "POST", body: workflowBody });
|
|
1518
|
+
const { code, error: workflowError } = await Utility.callEdgeFunction(false, supabase, `suprsend/trigger-workflow?user-id=${user.id}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(workflowBody) });
|
|
1495
1519
|
// If notification fails, revert the flag and return error
|
|
1496
1520
|
if (workflowError) {
|
|
1497
1521
|
await supabase.auth.updateUser({
|