@scalemule/nextjs 0.0.1 → 0.0.3

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.
@@ -2,6 +2,16 @@ import { cookies } from 'next/headers';
2
2
  import { NextResponse } from 'next/server';
3
3
  import { createHmac, timingSafeEqual } from 'crypto';
4
4
 
5
+ // src/types/index.ts
6
+ var ScaleMuleApiError = class extends Error {
7
+ constructor(error) {
8
+ super(error.message);
9
+ this.name = "ScaleMuleApiError";
10
+ this.code = error.code;
11
+ this.field = error.field;
12
+ }
13
+ };
14
+
5
15
  // src/server/context.ts
6
16
  function validateIP(ip) {
7
17
  if (!ip) return void 0;
@@ -542,22 +552,27 @@ var ScaleMuleServer = class {
542
552
  headers,
543
553
  body: formData
544
554
  });
545
- const data = await response.json();
555
+ const text = await response.text();
556
+ let responseData = null;
557
+ try {
558
+ responseData = text ? JSON.parse(text) : null;
559
+ } catch {
560
+ }
546
561
  if (!response.ok) {
547
- return {
548
- success: false,
549
- error: data.error || { code: "UPLOAD_FAILED", message: "Upload failed" }
550
- };
562
+ throw new ScaleMuleApiError(
563
+ responseData?.error || { code: "UPLOAD_FAILED", message: text || "Upload failed" }
564
+ );
551
565
  }
566
+ const data = responseData?.data !== void 0 ? responseData.data : responseData;
552
567
  return data;
553
568
  } catch (err) {
554
- return {
555
- success: false,
556
- error: {
557
- code: "UPLOAD_ERROR",
558
- message: err instanceof Error ? err.message : "Upload failed"
559
- }
560
- };
569
+ if (err instanceof ScaleMuleApiError) {
570
+ throw err;
571
+ }
572
+ throw new ScaleMuleApiError({
573
+ code: "UPLOAD_ERROR",
574
+ message: err instanceof Error ? err.message : "Upload failed"
575
+ });
561
576
  }
562
577
  }
563
578
  };
@@ -580,7 +595,7 @@ var ScaleMuleServer = class {
580
595
  * })
581
596
  *
582
597
  * // Store the secret for signature verification
583
- * console.log('Webhook secret:', result.data.secret)
598
+ * console.log('Webhook secret:', result.secret)
584
599
  * ```
585
600
  */
586
601
  create: async (data) => {
@@ -735,23 +750,29 @@ var ScaleMuleServer = class {
735
750
  headers,
736
751
  body: options.body ? JSON.stringify(options.body) : void 0
737
752
  });
738
- const data = await response.json();
753
+ const text = await response.text();
754
+ let responseData = null;
755
+ try {
756
+ responseData = text ? JSON.parse(text) : null;
757
+ } catch {
758
+ }
739
759
  if (!response.ok) {
740
- const error = data.error || {
760
+ const error = responseData?.error || {
741
761
  code: `HTTP_${response.status}`,
742
- message: data.message || response.statusText
762
+ message: responseData?.message || text || response.statusText
743
763
  };
744
- return { success: false, error };
764
+ throw new ScaleMuleApiError(error);
745
765
  }
766
+ const data = responseData?.data !== void 0 ? responseData.data : responseData;
746
767
  return data;
747
768
  } catch (err) {
748
- return {
749
- success: false,
750
- error: {
751
- code: "SERVER_ERROR",
752
- message: err instanceof Error ? err.message : "Request failed"
753
- }
754
- };
769
+ if (err instanceof ScaleMuleApiError) {
770
+ throw err;
771
+ }
772
+ throw new ScaleMuleApiError({
773
+ code: "SERVER_ERROR",
774
+ message: err instanceof Error ? err.message : "Request failed"
775
+ });
755
776
  }
756
777
  }
757
778
  };
@@ -1010,18 +1031,21 @@ function createAuthRoutes(config = {}) {
1010
1031
  if (!email || !password) {
1011
1032
  return errorResponse("VALIDATION_ERROR", "Email and password required", 400);
1012
1033
  }
1013
- const result = await sm.auth.register({ email, password, full_name, username, phone });
1014
- if (!result.success) {
1034
+ let registeredUser;
1035
+ try {
1036
+ registeredUser = await sm.auth.register({ email, password, full_name, username, phone });
1037
+ } catch (err) {
1038
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1015
1039
  return errorResponse(
1016
- result.error?.code || "REGISTER_FAILED",
1017
- result.error?.message || "Registration failed",
1040
+ apiErr?.code || "REGISTER_FAILED",
1041
+ apiErr?.message || "Registration failed",
1018
1042
  400
1019
1043
  );
1020
1044
  }
1021
- if (config.onRegister && result.data) {
1022
- await config.onRegister({ id: result.data.id, email: result.data.email });
1045
+ if (config.onRegister) {
1046
+ await config.onRegister({ id: registeredUser.id, email: registeredUser.email });
1023
1047
  }
1024
- return successResponse({ user: result.data, message: "Registration successful" }, 201);
1048
+ return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
1025
1049
  }
1026
1050
  // ==================== Login ====================
1027
1051
  case "login": {
@@ -1029,9 +1053,12 @@ function createAuthRoutes(config = {}) {
1029
1053
  if (!email || !password) {
1030
1054
  return errorResponse("VALIDATION_ERROR", "Email and password required", 400);
1031
1055
  }
1032
- const result = await sm.auth.login({ email, password, remember_me });
1033
- if (!result.success || !result.data) {
1034
- const errorCode = result.error?.code || "LOGIN_FAILED";
1056
+ let loginData;
1057
+ try {
1058
+ loginData = await sm.auth.login({ email, password, remember_me });
1059
+ } catch (err) {
1060
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1061
+ const errorCode = apiErr?.code || "LOGIN_FAILED";
1035
1062
  let status = 400;
1036
1063
  if (errorCode === "INVALID_CREDENTIALS" || errorCode === "UNAUTHORIZED") status = 401;
1037
1064
  if (["EMAIL_NOT_VERIFIED", "PHONE_NOT_VERIFIED", "ACCOUNT_LOCKED", "ACCOUNT_DISABLED", "MFA_REQUIRED"].includes(errorCode)) {
@@ -1039,17 +1066,17 @@ function createAuthRoutes(config = {}) {
1039
1066
  }
1040
1067
  return errorResponse(
1041
1068
  errorCode,
1042
- result.error?.message || "Login failed",
1069
+ apiErr?.message || "Login failed",
1043
1070
  status
1044
1071
  );
1045
1072
  }
1046
1073
  if (config.onLogin) {
1047
1074
  await config.onLogin({
1048
- id: result.data.user.id,
1049
- email: result.data.user.email
1075
+ id: loginData.user.id,
1076
+ email: loginData.user.email
1050
1077
  });
1051
1078
  }
1052
- return withSession(result.data, { user: result.data.user }, cookieOptions);
1079
+ return withSession(loginData, { user: loginData.user }, cookieOptions);
1053
1080
  }
1054
1081
  // ==================== Logout ====================
1055
1082
  case "logout": {
@@ -1077,11 +1104,13 @@ function createAuthRoutes(config = {}) {
1077
1104
  if (!token || !new_password) {
1078
1105
  return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
1079
1106
  }
1080
- const result = await sm.auth.resetPassword(token, new_password);
1081
- if (!result.success) {
1107
+ try {
1108
+ await sm.auth.resetPassword(token, new_password);
1109
+ } catch (err) {
1110
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1082
1111
  return errorResponse(
1083
- result.error?.code || "RESET_FAILED",
1084
- result.error?.message || "Password reset failed",
1112
+ apiErr?.code || "RESET_FAILED",
1113
+ apiErr?.message || "Password reset failed",
1085
1114
  400
1086
1115
  );
1087
1116
  }
@@ -1093,11 +1122,13 @@ function createAuthRoutes(config = {}) {
1093
1122
  if (!token) {
1094
1123
  return errorResponse("VALIDATION_ERROR", "Token required", 400);
1095
1124
  }
1096
- const result = await sm.auth.verifyEmail(token);
1097
- if (!result.success) {
1125
+ try {
1126
+ await sm.auth.verifyEmail(token);
1127
+ } catch (err) {
1128
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1098
1129
  return errorResponse(
1099
- result.error?.code || "VERIFY_FAILED",
1100
- result.error?.message || "Email verification failed",
1130
+ apiErr?.code || "VERIFY_FAILED",
1131
+ apiErr?.message || "Email verification failed",
1101
1132
  400
1102
1133
  );
1103
1134
  }
@@ -1109,12 +1140,14 @@ function createAuthRoutes(config = {}) {
1109
1140
  const { email } = body;
1110
1141
  const session = await getSession();
1111
1142
  if (email) {
1112
- const result2 = await sm.auth.resendVerification(email);
1113
- if (!result2.success) {
1143
+ try {
1144
+ await sm.auth.resendVerification(email);
1145
+ } catch (err) {
1146
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1114
1147
  return errorResponse(
1115
- result2.error?.code || "RESEND_FAILED",
1116
- result2.error?.message || "Failed to resend verification",
1117
- result2.error?.code === "RATE_LIMITED" ? 429 : 400
1148
+ apiErr?.code || "RESEND_FAILED",
1149
+ apiErr?.message || "Failed to resend verification",
1150
+ apiErr?.code === "RATE_LIMITED" ? 429 : 400
1118
1151
  );
1119
1152
  }
1120
1153
  return successResponse({ message: "Verification email sent" });
@@ -1122,11 +1155,13 @@ function createAuthRoutes(config = {}) {
1122
1155
  if (!session) {
1123
1156
  return errorResponse("UNAUTHORIZED", "Email or session required", 401);
1124
1157
  }
1125
- const result = await sm.auth.resendVerification(session.sessionToken);
1126
- if (!result.success) {
1158
+ try {
1159
+ await sm.auth.resendVerification(session.sessionToken);
1160
+ } catch (err) {
1161
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1127
1162
  return errorResponse(
1128
- result.error?.code || "RESEND_FAILED",
1129
- result.error?.message || "Failed to resend verification",
1163
+ apiErr?.code || "RESEND_FAILED",
1164
+ apiErr?.message || "Failed to resend verification",
1130
1165
  400
1131
1166
  );
1132
1167
  }
@@ -1138,15 +1173,17 @@ function createAuthRoutes(config = {}) {
1138
1173
  if (!session) {
1139
1174
  return errorResponse("UNAUTHORIZED", "Authentication required", 401);
1140
1175
  }
1141
- const result = await sm.auth.refresh(session.sessionToken);
1142
- if (!result.success || !result.data) {
1176
+ let refreshData;
1177
+ try {
1178
+ refreshData = await sm.auth.refresh(session.sessionToken);
1179
+ } catch {
1143
1180
  return clearSession(
1144
1181
  { message: "Session expired" },
1145
1182
  cookieOptions
1146
1183
  );
1147
1184
  }
1148
1185
  return withRefreshedSession(
1149
- result.data.session_token,
1186
+ refreshData.session_token,
1150
1187
  session.userId,
1151
1188
  { message: "Session refreshed" },
1152
1189
  cookieOptions
@@ -1162,15 +1199,17 @@ function createAuthRoutes(config = {}) {
1162
1199
  if (!current_password || !new_password) {
1163
1200
  return errorResponse("VALIDATION_ERROR", "Current and new password required", 400);
1164
1201
  }
1165
- const result = await sm.user.changePassword(
1166
- session.sessionToken,
1167
- current_password,
1168
- new_password
1169
- );
1170
- if (!result.success) {
1202
+ try {
1203
+ await sm.user.changePassword(
1204
+ session.sessionToken,
1205
+ current_password,
1206
+ new_password
1207
+ );
1208
+ } catch (err) {
1209
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1171
1210
  return errorResponse(
1172
- result.error?.code || "CHANGE_FAILED",
1173
- result.error?.message || "Failed to change password",
1211
+ apiErr?.code || "CHANGE_FAILED",
1212
+ apiErr?.message || "Failed to change password",
1174
1213
  400
1175
1214
  );
1176
1215
  }
@@ -1195,14 +1234,16 @@ function createAuthRoutes(config = {}) {
1195
1234
  if (!session) {
1196
1235
  return errorResponse("UNAUTHORIZED", "Authentication required", 401);
1197
1236
  }
1198
- const result = await sm.auth.me(session.sessionToken);
1199
- if (!result.success || !result.data) {
1237
+ let userData;
1238
+ try {
1239
+ userData = await sm.auth.me(session.sessionToken);
1240
+ } catch {
1200
1241
  return clearSession(
1201
1242
  { error: { code: "SESSION_EXPIRED", message: "Session expired" } },
1202
1243
  cookieOptions
1203
1244
  );
1204
1245
  }
1205
- return successResponse({ user: result.data });
1246
+ return successResponse({ user: userData });
1206
1247
  }
1207
1248
  // ==================== Get Session Status ====================
1208
1249
  case "session": {
@@ -1237,11 +1278,13 @@ function createAuthRoutes(config = {}) {
1237
1278
  if (!password) {
1238
1279
  return errorResponse("VALIDATION_ERROR", "Password required", 400);
1239
1280
  }
1240
- const result = await sm.user.deleteAccount(session.sessionToken, password);
1241
- if (!result.success) {
1281
+ try {
1282
+ await sm.user.deleteAccount(session.sessionToken, password);
1283
+ } catch (err) {
1284
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1242
1285
  return errorResponse(
1243
- result.error?.code || "DELETE_FAILED",
1244
- result.error?.message || "Failed to delete account",
1286
+ apiErr?.code || "DELETE_FAILED",
1287
+ apiErr?.message || "Failed to delete account",
1245
1288
  400
1246
1289
  );
1247
1290
  }
@@ -1269,15 +1312,18 @@ function createAuthRoutes(config = {}) {
1269
1312
  }
1270
1313
  const body = await request.json().catch(() => ({}));
1271
1314
  const { full_name, avatar_url } = body;
1272
- const result = await sm.user.update(session.sessionToken, { full_name, avatar_url });
1273
- if (!result.success || !result.data) {
1315
+ let updatedUser;
1316
+ try {
1317
+ updatedUser = await sm.user.update(session.sessionToken, { full_name, avatar_url });
1318
+ } catch (err) {
1319
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1274
1320
  return errorResponse(
1275
- result.error?.code || "UPDATE_FAILED",
1276
- result.error?.message || "Failed to update profile",
1321
+ apiErr?.code || "UPDATE_FAILED",
1322
+ apiErr?.message || "Failed to update profile",
1277
1323
  400
1278
1324
  );
1279
1325
  }
1280
- return successResponse({ user: result.data });
1326
+ return successResponse({ user: updatedUser });
1281
1327
  }
1282
1328
  default:
1283
1329
  return errorResponse("NOT_FOUND", `Unknown endpoint: ${path}`, 404);
@@ -1325,48 +1371,51 @@ function createAnalyticsRoutes(config = {}) {
1325
1371
  if (!event_name) {
1326
1372
  return errorResponse("VALIDATION_ERROR", "event_name is required", 400);
1327
1373
  }
1328
- const result = await sm.analytics.trackEvent(
1329
- {
1330
- event_name,
1331
- event_category,
1332
- properties,
1333
- user_id,
1334
- session_id,
1335
- anonymous_id,
1336
- session_duration_seconds,
1337
- page_url,
1338
- page_title,
1339
- referrer,
1340
- landing_page,
1341
- device_type,
1342
- device_brand,
1343
- device_model,
1344
- browser,
1345
- browser_version,
1346
- os,
1347
- os_version,
1348
- screen_resolution,
1349
- viewport_size,
1350
- utm_source,
1351
- utm_medium,
1352
- utm_campaign,
1353
- utm_term,
1354
- utm_content,
1355
- client_timestamp: client_timestamp || timestamp
1356
- },
1357
- { clientContext }
1358
- );
1359
- if (!result.success) {
1374
+ let trackResult;
1375
+ try {
1376
+ trackResult = await sm.analytics.trackEvent(
1377
+ {
1378
+ event_name,
1379
+ event_category,
1380
+ properties,
1381
+ user_id,
1382
+ session_id,
1383
+ anonymous_id,
1384
+ session_duration_seconds,
1385
+ page_url,
1386
+ page_title,
1387
+ referrer,
1388
+ landing_page,
1389
+ device_type,
1390
+ device_brand,
1391
+ device_model,
1392
+ browser,
1393
+ browser_version,
1394
+ os,
1395
+ os_version,
1396
+ screen_resolution,
1397
+ viewport_size,
1398
+ utm_source,
1399
+ utm_medium,
1400
+ utm_campaign,
1401
+ utm_term,
1402
+ utm_content,
1403
+ client_timestamp: client_timestamp || timestamp
1404
+ },
1405
+ { clientContext }
1406
+ );
1407
+ } catch (err) {
1408
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1360
1409
  return errorResponse(
1361
- result.error?.code || "TRACK_FAILED",
1362
- result.error?.message || "Failed to track event",
1410
+ apiErr?.code || "TRACK_FAILED",
1411
+ apiErr?.message || "Failed to track event",
1363
1412
  400
1364
1413
  );
1365
1414
  }
1366
1415
  if (config.onEvent) {
1367
- await config.onEvent({ event_name, session_id: result.data?.session_id });
1416
+ await config.onEvent({ event_name, session_id: trackResult?.session_id });
1368
1417
  }
1369
- return successResponse({ tracked: result.data?.tracked || 1, session_id: result.data?.session_id });
1418
+ return successResponse({ tracked: trackResult?.tracked || 1, session_id: trackResult?.session_id });
1370
1419
  };
1371
1420
  const POST = async (request, context) => {
1372
1421
  try {
@@ -1393,15 +1442,18 @@ function createAnalyticsRoutes(config = {}) {
1393
1442
  if (events.length > 100) {
1394
1443
  return errorResponse("VALIDATION_ERROR", "Maximum 100 events per batch", 400);
1395
1444
  }
1396
- const result = await sm.analytics.trackBatch(events, { clientContext });
1397
- if (!result.success) {
1445
+ let batchResult;
1446
+ try {
1447
+ batchResult = await sm.analytics.trackBatch(events, { clientContext });
1448
+ } catch (err) {
1449
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1398
1450
  return errorResponse(
1399
- result.error?.code || "BATCH_FAILED",
1400
- result.error?.message || "Failed to track events",
1451
+ apiErr?.code || "BATCH_FAILED",
1452
+ apiErr?.message || "Failed to track events",
1401
1453
  400
1402
1454
  );
1403
1455
  }
1404
- return successResponse({ tracked: result.data?.tracked || events.length });
1456
+ return successResponse({ tracked: batchResult?.tracked || events.length });
1405
1457
  }
1406
1458
  // ==================== Track Page View ====================
1407
1459
  case "page-view":
@@ -1410,21 +1462,24 @@ function createAnalyticsRoutes(config = {}) {
1410
1462
  if (!page_url) {
1411
1463
  return errorResponse("VALIDATION_ERROR", "page_url is required", 400);
1412
1464
  }
1413
- const result = await sm.analytics.trackPageView(
1414
- { page_url, page_title, referrer, session_id, user_id },
1415
- { clientContext }
1416
- );
1417
- if (!result.success) {
1465
+ let pageViewResult;
1466
+ try {
1467
+ pageViewResult = await sm.analytics.trackPageView(
1468
+ { page_url, page_title, referrer, session_id, user_id },
1469
+ { clientContext }
1470
+ );
1471
+ } catch (err) {
1472
+ const apiErr = err instanceof ScaleMuleApiError ? err : null;
1418
1473
  return errorResponse(
1419
- result.error?.code || "TRACK_FAILED",
1420
- result.error?.message || "Failed to track page view",
1474
+ apiErr?.code || "TRACK_FAILED",
1475
+ apiErr?.message || "Failed to track page view",
1421
1476
  400
1422
1477
  );
1423
1478
  }
1424
1479
  if (config.onEvent) {
1425
- await config.onEvent({ event_name: "page_viewed", session_id: result.data?.session_id });
1480
+ await config.onEvent({ event_name: "page_viewed", session_id: pageViewResult?.session_id });
1426
1481
  }
1427
- return successResponse({ tracked: result.data?.tracked || 1, session_id: result.data?.session_id });
1482
+ return successResponse({ tracked: pageViewResult?.tracked || 1, session_id: pageViewResult?.session_id });
1428
1483
  }
1429
1484
  default:
1430
1485
  return errorResponse("NOT_FOUND", `Unknown endpoint: ${path}`, 404);
@@ -1487,18 +1542,22 @@ function errorCodeToStatus(code) {
1487
1542
  return CODE_TO_STATUS[code.toLowerCase()] || 400;
1488
1543
  }
1489
1544
  function unwrap(result) {
1490
- if (result.error || result.success === false) {
1491
- const err = result.error;
1492
- const code = err?.code || "UNKNOWN_ERROR";
1493
- const status = err?.status || errorCodeToStatus(code);
1494
- throw new ScaleMuleError(
1495
- code,
1496
- err?.message || "An error occurred",
1497
- status,
1498
- err?.details
1499
- );
1545
+ if (result !== null && result !== void 0 && typeof result === "object" && ("success" in result || "error" in result) && "data" in result) {
1546
+ const envelope = result;
1547
+ if (envelope.error || envelope.success === false) {
1548
+ const err = envelope.error;
1549
+ const code = err?.code || "UNKNOWN_ERROR";
1550
+ const status = err?.status || errorCodeToStatus(code);
1551
+ throw new ScaleMuleError(
1552
+ code,
1553
+ err?.message || "An error occurred",
1554
+ status,
1555
+ err?.details
1556
+ );
1557
+ }
1558
+ return envelope.data;
1500
1559
  }
1501
- return result.data;
1560
+ return result;
1502
1561
  }
1503
1562
 
1504
1563
  // src/server/handler.ts
@@ -1576,12 +1635,9 @@ async function registerVideoWebhook(url, options) {
1576
1635
  url,
1577
1636
  events: options?.events || ["video.ready", "video.failed"]
1578
1637
  });
1579
- if (!result.success || !result.data) {
1580
- throw new Error(result.error?.message || "Failed to register webhook");
1581
- }
1582
1638
  return {
1583
- id: result.data.id,
1584
- secret: result.data.secret
1639
+ id: result.id,
1640
+ secret: result.secret
1585
1641
  };
1586
1642
  }
1587
1643
  function createWebhookRoutes(config = {}) {
@@ -1722,13 +1778,7 @@ function createAuthMiddleware(config = {}) {
1722
1778
  if (!skipValidation) {
1723
1779
  try {
1724
1780
  const sm = createServerClient();
1725
- const result = await sm.auth.me(session.sessionToken);
1726
- if (!result.success) {
1727
- const response = NextResponse.redirect(new URL(redirectTo, request.url));
1728
- response.cookies.delete(SESSION_COOKIE_NAME);
1729
- response.cookies.delete(USER_ID_COOKIE_NAME);
1730
- return response;
1731
- }
1781
+ await sm.auth.me(session.sessionToken);
1732
1782
  } catch (error) {
1733
1783
  console.error("[ScaleMule Middleware] Session validation failed, blocking request:", error);
1734
1784
  const response = NextResponse.redirect(new URL(redirectTo, request.url));
@@ -1819,22 +1869,18 @@ async function getAppSecret(key) {
1819
1869
  try {
1820
1870
  const client = createServerClient();
1821
1871
  const result = await client.secrets.get(key);
1822
- if (!result.success) {
1823
- if (result.error?.code === "SECRET_NOT_FOUND") {
1824
- return void 0;
1825
- }
1826
- console.error(`[ScaleMule Secrets] Failed to fetch ${key}:`, result.error);
1827
- return void 0;
1828
- }
1829
- if (!noCache && result.data) {
1872
+ if (!noCache && result) {
1830
1873
  secretsCache[key] = {
1831
- value: result.data.value,
1832
- version: result.data.version,
1874
+ value: result.value,
1875
+ version: result.version,
1833
1876
  cachedAt: Date.now()
1834
1877
  };
1835
1878
  }
1836
- return result.data?.value;
1879
+ return result?.value;
1837
1880
  } catch (error) {
1881
+ if (error instanceof ScaleMuleApiError && error.code === "SECRET_NOT_FOUND") {
1882
+ return void 0;
1883
+ }
1838
1884
  console.error(`[ScaleMule Secrets] Error fetching ${key}:`, error);
1839
1885
  return void 0;
1840
1886
  }
@@ -1882,24 +1928,20 @@ async function getBundle(key, resolve = true) {
1882
1928
  try {
1883
1929
  const client = createServerClient();
1884
1930
  const result = await client.bundles.get(key, resolve);
1885
- if (!result.success) {
1886
- if (result.error?.code === "BUNDLE_NOT_FOUND") {
1887
- return void 0;
1888
- }
1889
- console.error(`[ScaleMule Bundles] Failed to fetch ${key}:`, result.error);
1890
- return void 0;
1891
- }
1892
- if (!noCache && result.data) {
1931
+ if (!noCache && result) {
1893
1932
  bundlesCache[key] = {
1894
- type: result.data.type,
1895
- data: result.data.data,
1896
- version: result.data.version,
1897
- inheritsFrom: result.data.inherits_from,
1933
+ type: result.type,
1934
+ data: result.data,
1935
+ version: result.version,
1936
+ inheritsFrom: result.inherits_from,
1898
1937
  cachedAt: Date.now()
1899
1938
  };
1900
1939
  }
1901
- return result.data?.data;
1940
+ return result?.data;
1902
1941
  } catch (error) {
1942
+ if (error instanceof ScaleMuleApiError && error.code === "BUNDLE_NOT_FOUND") {
1943
+ return void 0;
1944
+ }
1903
1945
  console.error(`[ScaleMule Bundles] Error fetching ${key}:`, error);
1904
1946
  return void 0;
1905
1947
  }
@@ -1,2 +1,2 @@
1
- export { h as createWebhookHandler } from '../webhook-handler-C-5_Ey1T.mjs';
2
- import '../index-BkacIKdu.mjs';
1
+ export { h as createWebhookHandler } from '../webhook-handler-DCSwldKC.mjs';
2
+ import '../index-9v0SaLgg.mjs';
@@ -1,2 +1,2 @@
1
- export { h as createWebhookHandler } from '../webhook-handler-BPNqhuwL.js';
2
- import '../index-BkacIKdu.js';
1
+ export { h as createWebhookHandler } from '../webhook-handler-Ymeice_x.js';
2
+ import '../index-9v0SaLgg.js';