@scalemule/nextjs 0.0.6 → 0.0.8
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/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -4
- package/dist/client.mjs +2 -4
- package/dist/{index-9v0SaLgg.d.mts → index-jomBa89d.d.mts} +2 -2
- package/dist/{index-9v0SaLgg.d.ts → index-jomBa89d.d.ts} +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -9
- package/dist/index.mjs +25 -9
- package/dist/server/auth.js +86 -14
- package/dist/server/auth.mjs +86 -14
- package/dist/server/index.d.mts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +22 -14
- package/dist/server/index.mjs +22 -14
- package/dist/server/webhook-handler.d.mts +2 -2
- package/dist/server/webhook-handler.d.ts +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/{webhook-handler-Ymeice_x.d.ts → webhook-handler-BzBvYbZU.d.mts} +13 -5
- package/dist/{webhook-handler-DCSwldKC.d.mts → webhook-handler-tcJtRpkE.d.ts} +13 -5
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -482,10 +482,8 @@ var ScaleMuleClient = class {
|
|
|
482
482
|
} catch {
|
|
483
483
|
}
|
|
484
484
|
if (!response.ok) {
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
message: responseData?.message || text || response.statusText
|
|
488
|
-
};
|
|
485
|
+
const rawError = responseData?.error;
|
|
486
|
+
const error = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
489
487
|
if (attempt < maxRetries && RETRYABLE_STATUS_CODES.has(response.status)) {
|
|
490
488
|
lastError = error;
|
|
491
489
|
const delay = getBackoffDelay(attempt);
|
package/dist/client.mjs
CHANGED
|
@@ -480,10 +480,8 @@ var ScaleMuleClient = class {
|
|
|
480
480
|
} catch {
|
|
481
481
|
}
|
|
482
482
|
if (!response.ok) {
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
message: responseData?.message || text || response.statusText
|
|
486
|
-
};
|
|
483
|
+
const rawError = responseData?.error;
|
|
484
|
+
const error = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
487
485
|
if (attempt < maxRetries && RETRYABLE_STATUS_CODES.has(response.status)) {
|
|
488
486
|
lastError = error;
|
|
489
487
|
const delay = getBackoffDelay(attempt);
|
|
@@ -412,8 +412,8 @@ interface UseAuthReturn {
|
|
|
412
412
|
resetPassword: (token: string, newPassword: string) => Promise<void>;
|
|
413
413
|
/** Verify email with token */
|
|
414
414
|
verifyEmail: (token: string) => Promise<void>;
|
|
415
|
-
/** Resend verification email */
|
|
416
|
-
resendVerification: () => Promise<void>;
|
|
415
|
+
/** Resend verification email (optional email for unauthenticated resend) */
|
|
416
|
+
resendVerification: (email?: string) => Promise<void>;
|
|
417
417
|
/** Refresh session token */
|
|
418
418
|
refreshSession: () => Promise<void>;
|
|
419
419
|
/** Start OAuth flow for a provider */
|
|
@@ -412,8 +412,8 @@ interface UseAuthReturn {
|
|
|
412
412
|
resetPassword: (token: string, newPassword: string) => Promise<void>;
|
|
413
413
|
/** Verify email with token */
|
|
414
414
|
verifyEmail: (token: string) => Promise<void>;
|
|
415
|
-
/** Resend verification email */
|
|
416
|
-
resendVerification: () => Promise<void>;
|
|
415
|
+
/** Resend verification email (optional email for unauthenticated resend) */
|
|
416
|
+
resendVerification: (email?: string) => Promise<void>;
|
|
417
417
|
/** Refresh session token */
|
|
418
418
|
refreshSession: () => Promise<void>;
|
|
419
419
|
/** Start OAuth flow for a provider */
|
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { ScaleMuleClient } from './client.mjs';
|
|
4
4
|
export { ClientConfig, RequestOptions, createClient } from './client.mjs';
|
|
5
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
6
|
-
export { a2 as AccountBalance, a9 as AnalyticsEvent, k as ApiResponse, af as BatchTrackRequest, a3 as BillingPayment, a5 as BillingPayout, a4 as BillingRefund, a7 as BillingTransaction, r as ChangeEmailRequest, C as ChangePasswordRequest, $ as ClientContext, a1 as ConnectedAccount, D as DeviceFingerprint, ac as DeviceInfo, ad as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, x as LinkedAccount, T as ListFilesResponse, n as LoginDeviceInfo, l as LoginRequest, m as LoginResponseWithMFA, o as LoginRiskInfo, G as MFAChallengeResponse, M as MFAMethod, B as MFASMSSetupResponse, y as MFASetupRequest, H as MFAStatus, z as MFATOTPSetupResponse, E as MFAVerifyRequest, v as OAuthCallbackRequest, w as OAuthCallbackResponse, t as OAuthConfig, O as OAuthProvider, u as OAuthStartResponse, aa as PageViewData, a6 as PayoutSchedule, K as PhoneLoginRequest, I as PhoneSendCodeRequest, J as PhoneVerifyRequest, P as Profile, p as RefreshResponse, R as RegisterRequest, q as ResetPasswordRequest, h as ScaleMuleApiError, i as ScaleMuleEnvironment, s as Session, _ as SignedUploadCompleteRequest, Y as SignedUploadRequest, Z as SignedUploadResponse, X as SignedUploadUrl, j as StorageAdapter, N as StorageFile, ae as TrackEventResponse, a8 as TransactionSummary, ab as UTMParams, a0 as UpdateProfileRequest, Q as UploadOptions, W as UploadResponse, V as VerifyEmailRequest } from './index-
|
|
5
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-jomBa89d.mjs';
|
|
6
|
+
export { a2 as AccountBalance, a9 as AnalyticsEvent, k as ApiResponse, af as BatchTrackRequest, a3 as BillingPayment, a5 as BillingPayout, a4 as BillingRefund, a7 as BillingTransaction, r as ChangeEmailRequest, C as ChangePasswordRequest, $ as ClientContext, a1 as ConnectedAccount, D as DeviceFingerprint, ac as DeviceInfo, ad as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, x as LinkedAccount, T as ListFilesResponse, n as LoginDeviceInfo, l as LoginRequest, m as LoginResponseWithMFA, o as LoginRiskInfo, G as MFAChallengeResponse, M as MFAMethod, B as MFASMSSetupResponse, y as MFASetupRequest, H as MFAStatus, z as MFATOTPSetupResponse, E as MFAVerifyRequest, v as OAuthCallbackRequest, w as OAuthCallbackResponse, t as OAuthConfig, O as OAuthProvider, u as OAuthStartResponse, aa as PageViewData, a6 as PayoutSchedule, K as PhoneLoginRequest, I as PhoneSendCodeRequest, J as PhoneVerifyRequest, P as Profile, p as RefreshResponse, R as RegisterRequest, q as ResetPasswordRequest, h as ScaleMuleApiError, i as ScaleMuleEnvironment, s as Session, _ as SignedUploadCompleteRequest, Y as SignedUploadRequest, Z as SignedUploadResponse, X as SignedUploadUrl, j as StorageAdapter, N as StorageFile, ae as TrackEventResponse, a8 as TransactionSummary, ab as UTMParams, a0 as UpdateProfileRequest, Q as UploadOptions, W as UploadResponse, V as VerifyEmailRequest } from './index-jomBa89d.mjs';
|
|
7
7
|
|
|
8
8
|
interface ScaleMuleContextValue {
|
|
9
9
|
/** The API client instance */
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { ScaleMuleClient } from './client.js';
|
|
4
4
|
export { ClientConfig, RequestOptions, createClient } from './client.js';
|
|
5
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
6
|
-
export { a2 as AccountBalance, a9 as AnalyticsEvent, k as ApiResponse, af as BatchTrackRequest, a3 as BillingPayment, a5 as BillingPayout, a4 as BillingRefund, a7 as BillingTransaction, r as ChangeEmailRequest, C as ChangePasswordRequest, $ as ClientContext, a1 as ConnectedAccount, D as DeviceFingerprint, ac as DeviceInfo, ad as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, x as LinkedAccount, T as ListFilesResponse, n as LoginDeviceInfo, l as LoginRequest, m as LoginResponseWithMFA, o as LoginRiskInfo, G as MFAChallengeResponse, M as MFAMethod, B as MFASMSSetupResponse, y as MFASetupRequest, H as MFAStatus, z as MFATOTPSetupResponse, E as MFAVerifyRequest, v as OAuthCallbackRequest, w as OAuthCallbackResponse, t as OAuthConfig, O as OAuthProvider, u as OAuthStartResponse, aa as PageViewData, a6 as PayoutSchedule, K as PhoneLoginRequest, I as PhoneSendCodeRequest, J as PhoneVerifyRequest, P as Profile, p as RefreshResponse, R as RegisterRequest, q as ResetPasswordRequest, h as ScaleMuleApiError, i as ScaleMuleEnvironment, s as Session, _ as SignedUploadCompleteRequest, Y as SignedUploadRequest, Z as SignedUploadResponse, X as SignedUploadUrl, j as StorageAdapter, N as StorageFile, ae as TrackEventResponse, a8 as TransactionSummary, ab as UTMParams, a0 as UpdateProfileRequest, Q as UploadOptions, W as UploadResponse, V as VerifyEmailRequest } from './index-
|
|
5
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-jomBa89d.js';
|
|
6
|
+
export { a2 as AccountBalance, a9 as AnalyticsEvent, k as ApiResponse, af as BatchTrackRequest, a3 as BillingPayment, a5 as BillingPayout, a4 as BillingRefund, a7 as BillingTransaction, r as ChangeEmailRequest, C as ChangePasswordRequest, $ as ClientContext, a1 as ConnectedAccount, D as DeviceFingerprint, ac as DeviceInfo, ad as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, x as LinkedAccount, T as ListFilesResponse, n as LoginDeviceInfo, l as LoginRequest, m as LoginResponseWithMFA, o as LoginRiskInfo, G as MFAChallengeResponse, M as MFAMethod, B as MFASMSSetupResponse, y as MFASetupRequest, H as MFAStatus, z as MFATOTPSetupResponse, E as MFAVerifyRequest, v as OAuthCallbackRequest, w as OAuthCallbackResponse, t as OAuthConfig, O as OAuthProvider, u as OAuthStartResponse, aa as PageViewData, a6 as PayoutSchedule, K as PhoneLoginRequest, I as PhoneSendCodeRequest, J as PhoneVerifyRequest, P as Profile, p as RefreshResponse, R as RegisterRequest, q as ResetPasswordRequest, h as ScaleMuleApiError, i as ScaleMuleEnvironment, s as Session, _ as SignedUploadCompleteRequest, Y as SignedUploadRequest, Z as SignedUploadResponse, X as SignedUploadUrl, j as StorageAdapter, N as StorageFile, ae as TrackEventResponse, a8 as TransactionSummary, ab as UTMParams, a0 as UpdateProfileRequest, Q as UploadOptions, W as UploadResponse, V as VerifyEmailRequest } from './index-jomBa89d.js';
|
|
7
7
|
|
|
8
8
|
interface ScaleMuleContextValue {
|
|
9
9
|
/** The API client instance */
|
package/dist/index.js
CHANGED
|
@@ -487,10 +487,8 @@ var ScaleMuleClient = class {
|
|
|
487
487
|
} catch {
|
|
488
488
|
}
|
|
489
489
|
if (!response.ok) {
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
message: responseData?.message || text || response.statusText
|
|
493
|
-
};
|
|
490
|
+
const rawError = responseData?.error;
|
|
491
|
+
const error = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
494
492
|
if (attempt < maxRetries && RETRYABLE_STATUS_CODES.has(response.status)) {
|
|
495
493
|
lastError = error;
|
|
496
494
|
const delay = getBackoffDelay(attempt);
|
|
@@ -963,6 +961,9 @@ function useAuth() {
|
|
|
963
961
|
setError(err);
|
|
964
962
|
throw err;
|
|
965
963
|
}
|
|
964
|
+
if (response.data.sessionToken) {
|
|
965
|
+
await client.setSession(response.data.sessionToken, response.data.userId || response.data.user?.id || "");
|
|
966
|
+
}
|
|
966
967
|
return response.data.user;
|
|
967
968
|
}
|
|
968
969
|
try {
|
|
@@ -1001,6 +1002,11 @@ function useAuth() {
|
|
|
1001
1002
|
if (responseUser) {
|
|
1002
1003
|
setUser(responseUser);
|
|
1003
1004
|
}
|
|
1005
|
+
const sessionToken = "sessionToken" in loginData2 ? loginData2.sessionToken : void 0;
|
|
1006
|
+
const userId = "userId" in loginData2 ? loginData2.userId : void 0;
|
|
1007
|
+
if (sessionToken) {
|
|
1008
|
+
await client.setSession(sessionToken, userId || responseUser?.id || "");
|
|
1009
|
+
}
|
|
1004
1010
|
return response.data;
|
|
1005
1011
|
}
|
|
1006
1012
|
let loginResult;
|
|
@@ -1134,10 +1140,11 @@ function useAuth() {
|
|
|
1134
1140
|
},
|
|
1135
1141
|
[client, user, setUser, setError, authProxyUrl]
|
|
1136
1142
|
);
|
|
1137
|
-
const resendVerification = react.useCallback(async () => {
|
|
1143
|
+
const resendVerification = react.useCallback(async (email) => {
|
|
1138
1144
|
setError(null);
|
|
1139
1145
|
if (authProxyUrl) {
|
|
1140
|
-
const
|
|
1146
|
+
const body = email ? { email } : user ? {} : void 0;
|
|
1147
|
+
const response = await proxyFetch(authProxyUrl, "resend-verification", { body });
|
|
1141
1148
|
if (!response.success) {
|
|
1142
1149
|
const err = response.error || {
|
|
1143
1150
|
code: "RESEND_FAILED",
|
|
@@ -1147,15 +1154,19 @@ function useAuth() {
|
|
|
1147
1154
|
throw err;
|
|
1148
1155
|
}
|
|
1149
1156
|
} else {
|
|
1150
|
-
if (!user) {
|
|
1157
|
+
if (!user && !email) {
|
|
1151
1158
|
const err = {
|
|
1152
1159
|
code: "NOT_AUTHENTICATED",
|
|
1153
|
-
message: "Must be logged in to resend verification"
|
|
1160
|
+
message: "Must be logged in or provide email to resend verification"
|
|
1154
1161
|
};
|
|
1155
1162
|
throw err;
|
|
1156
1163
|
}
|
|
1157
1164
|
try {
|
|
1158
|
-
|
|
1165
|
+
if (email && !user) {
|
|
1166
|
+
await client.post("/v1/auth/resend-verification", { email });
|
|
1167
|
+
} else {
|
|
1168
|
+
await client.post("/v1/auth/resend-verification");
|
|
1169
|
+
}
|
|
1159
1170
|
} catch (err) {
|
|
1160
1171
|
if (err instanceof ScaleMuleApiError) {
|
|
1161
1172
|
setError(err);
|
|
@@ -1506,6 +1517,11 @@ function useAuth() {
|
|
|
1506
1517
|
if (responseUser) {
|
|
1507
1518
|
setUser(responseUser);
|
|
1508
1519
|
}
|
|
1520
|
+
const sessionToken = "sessionToken" in loginData ? loginData.sessionToken : void 0;
|
|
1521
|
+
const userId = "userId" in loginData ? loginData.userId : void 0;
|
|
1522
|
+
if (sessionToken) {
|
|
1523
|
+
await client.setSession(sessionToken, userId || responseUser?.id || "");
|
|
1524
|
+
}
|
|
1509
1525
|
return response.data;
|
|
1510
1526
|
}
|
|
1511
1527
|
let phoneLoginData;
|
package/dist/index.mjs
CHANGED
|
@@ -485,10 +485,8 @@ var ScaleMuleClient = class {
|
|
|
485
485
|
} catch {
|
|
486
486
|
}
|
|
487
487
|
if (!response.ok) {
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
message: responseData?.message || text || response.statusText
|
|
491
|
-
};
|
|
488
|
+
const rawError = responseData?.error;
|
|
489
|
+
const error = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
492
490
|
if (attempt < maxRetries && RETRYABLE_STATUS_CODES.has(response.status)) {
|
|
493
491
|
lastError = error;
|
|
494
492
|
const delay = getBackoffDelay(attempt);
|
|
@@ -961,6 +959,9 @@ function useAuth() {
|
|
|
961
959
|
setError(err);
|
|
962
960
|
throw err;
|
|
963
961
|
}
|
|
962
|
+
if (response.data.sessionToken) {
|
|
963
|
+
await client.setSession(response.data.sessionToken, response.data.userId || response.data.user?.id || "");
|
|
964
|
+
}
|
|
964
965
|
return response.data.user;
|
|
965
966
|
}
|
|
966
967
|
try {
|
|
@@ -999,6 +1000,11 @@ function useAuth() {
|
|
|
999
1000
|
if (responseUser) {
|
|
1000
1001
|
setUser(responseUser);
|
|
1001
1002
|
}
|
|
1003
|
+
const sessionToken = "sessionToken" in loginData2 ? loginData2.sessionToken : void 0;
|
|
1004
|
+
const userId = "userId" in loginData2 ? loginData2.userId : void 0;
|
|
1005
|
+
if (sessionToken) {
|
|
1006
|
+
await client.setSession(sessionToken, userId || responseUser?.id || "");
|
|
1007
|
+
}
|
|
1002
1008
|
return response.data;
|
|
1003
1009
|
}
|
|
1004
1010
|
let loginResult;
|
|
@@ -1132,10 +1138,11 @@ function useAuth() {
|
|
|
1132
1138
|
},
|
|
1133
1139
|
[client, user, setUser, setError, authProxyUrl]
|
|
1134
1140
|
);
|
|
1135
|
-
const resendVerification = useCallback(async () => {
|
|
1141
|
+
const resendVerification = useCallback(async (email) => {
|
|
1136
1142
|
setError(null);
|
|
1137
1143
|
if (authProxyUrl) {
|
|
1138
|
-
const
|
|
1144
|
+
const body = email ? { email } : user ? {} : void 0;
|
|
1145
|
+
const response = await proxyFetch(authProxyUrl, "resend-verification", { body });
|
|
1139
1146
|
if (!response.success) {
|
|
1140
1147
|
const err = response.error || {
|
|
1141
1148
|
code: "RESEND_FAILED",
|
|
@@ -1145,15 +1152,19 @@ function useAuth() {
|
|
|
1145
1152
|
throw err;
|
|
1146
1153
|
}
|
|
1147
1154
|
} else {
|
|
1148
|
-
if (!user) {
|
|
1155
|
+
if (!user && !email) {
|
|
1149
1156
|
const err = {
|
|
1150
1157
|
code: "NOT_AUTHENTICATED",
|
|
1151
|
-
message: "Must be logged in to resend verification"
|
|
1158
|
+
message: "Must be logged in or provide email to resend verification"
|
|
1152
1159
|
};
|
|
1153
1160
|
throw err;
|
|
1154
1161
|
}
|
|
1155
1162
|
try {
|
|
1156
|
-
|
|
1163
|
+
if (email && !user) {
|
|
1164
|
+
await client.post("/v1/auth/resend-verification", { email });
|
|
1165
|
+
} else {
|
|
1166
|
+
await client.post("/v1/auth/resend-verification");
|
|
1167
|
+
}
|
|
1157
1168
|
} catch (err) {
|
|
1158
1169
|
if (err instanceof ScaleMuleApiError) {
|
|
1159
1170
|
setError(err);
|
|
@@ -1504,6 +1515,11 @@ function useAuth() {
|
|
|
1504
1515
|
if (responseUser) {
|
|
1505
1516
|
setUser(responseUser);
|
|
1506
1517
|
}
|
|
1518
|
+
const sessionToken = "sessionToken" in loginData ? loginData.sessionToken : void 0;
|
|
1519
|
+
const userId = "userId" in loginData ? loginData.userId : void 0;
|
|
1520
|
+
if (sessionToken) {
|
|
1521
|
+
await client.setSession(sessionToken, userId || responseUser?.id || "");
|
|
1522
|
+
}
|
|
1507
1523
|
return response.data;
|
|
1508
1524
|
}
|
|
1509
1525
|
let phoneLoginData;
|
package/dist/server/auth.js
CHANGED
|
@@ -14,6 +14,70 @@ var ScaleMuleApiError = class extends Error {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
// src/server/context.ts
|
|
17
|
+
function validateIP(ip) {
|
|
18
|
+
if (!ip) return void 0;
|
|
19
|
+
const trimmed = ip.trim();
|
|
20
|
+
if (!trimmed) return void 0;
|
|
21
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
22
|
+
const ipv6Regex = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,7}:$|^(?:[0-9a-fA-F]{1,4}:){0,6}::(?:[0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}$/;
|
|
23
|
+
const ipv4MappedRegex = /^::ffff:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i;
|
|
24
|
+
if (ipv4Regex.test(trimmed) || ipv6Regex.test(trimmed) || ipv4MappedRegex.test(trimmed)) {
|
|
25
|
+
return trimmed;
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
function extractClientContext(request) {
|
|
30
|
+
const headers = request.headers;
|
|
31
|
+
let ip;
|
|
32
|
+
const cfConnectingIp = headers.get("cf-connecting-ip");
|
|
33
|
+
if (cfConnectingIp) {
|
|
34
|
+
ip = validateIP(cfConnectingIp);
|
|
35
|
+
}
|
|
36
|
+
if (!ip) {
|
|
37
|
+
const doConnectingIp = headers.get("do-connecting-ip");
|
|
38
|
+
if (doConnectingIp) {
|
|
39
|
+
ip = validateIP(doConnectingIp);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!ip) {
|
|
43
|
+
const realIp = headers.get("x-real-ip");
|
|
44
|
+
if (realIp) {
|
|
45
|
+
ip = validateIP(realIp);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!ip) {
|
|
49
|
+
const forwardedFor = headers.get("x-forwarded-for");
|
|
50
|
+
if (forwardedFor) {
|
|
51
|
+
const firstIp = forwardedFor.split(",")[0]?.trim();
|
|
52
|
+
ip = validateIP(firstIp);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!ip) {
|
|
56
|
+
const vercelForwarded = headers.get("x-vercel-forwarded-for");
|
|
57
|
+
if (vercelForwarded) {
|
|
58
|
+
const firstIp = vercelForwarded.split(",")[0]?.trim();
|
|
59
|
+
ip = validateIP(firstIp);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!ip) {
|
|
63
|
+
const trueClientIp = headers.get("true-client-ip");
|
|
64
|
+
if (trueClientIp) {
|
|
65
|
+
ip = validateIP(trueClientIp);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!ip && request.ip) {
|
|
69
|
+
ip = validateIP(request.ip);
|
|
70
|
+
}
|
|
71
|
+
const userAgent = headers.get("user-agent") || void 0;
|
|
72
|
+
const deviceFingerprint = headers.get("x-device-fingerprint") || void 0;
|
|
73
|
+
const referrer = headers.get("referer") || void 0;
|
|
74
|
+
return {
|
|
75
|
+
ip,
|
|
76
|
+
userAgent,
|
|
77
|
+
deviceFingerprint,
|
|
78
|
+
referrer
|
|
79
|
+
};
|
|
80
|
+
}
|
|
17
81
|
function buildClientContextHeaders(context) {
|
|
18
82
|
const headers = {};
|
|
19
83
|
if (!context) {
|
|
@@ -54,14 +118,14 @@ var ScaleMuleServer = class {
|
|
|
54
118
|
/**
|
|
55
119
|
* Register a new user
|
|
56
120
|
*/
|
|
57
|
-
register: async (data) => {
|
|
58
|
-
return this.request("POST", "/v1/auth/register", { body: data });
|
|
121
|
+
register: async (data, options) => {
|
|
122
|
+
return this.request("POST", "/v1/auth/register", { body: data, clientContext: options?.clientContext });
|
|
59
123
|
},
|
|
60
124
|
/**
|
|
61
125
|
* Login user - returns session token (store in HTTP-only cookie)
|
|
62
126
|
*/
|
|
63
|
-
login: async (data) => {
|
|
64
|
-
return this.request("POST", "/v1/auth/login", { body: data });
|
|
127
|
+
login: async (data, options) => {
|
|
128
|
+
return this.request("POST", "/v1/auth/login", { body: data, clientContext: options?.clientContext });
|
|
65
129
|
},
|
|
66
130
|
/**
|
|
67
131
|
* Logout user
|
|
@@ -88,15 +152,16 @@ var ScaleMuleServer = class {
|
|
|
88
152
|
/**
|
|
89
153
|
* Request password reset email
|
|
90
154
|
*/
|
|
91
|
-
forgotPassword: async (email) => {
|
|
92
|
-
return this.request("POST", "/v1/auth/forgot-password", { body: { email } });
|
|
155
|
+
forgotPassword: async (email, options) => {
|
|
156
|
+
return this.request("POST", "/v1/auth/forgot-password", { body: { email }, clientContext: options?.clientContext });
|
|
93
157
|
},
|
|
94
158
|
/**
|
|
95
159
|
* Reset password with token
|
|
96
160
|
*/
|
|
97
|
-
resetPassword: async (token, newPassword) => {
|
|
161
|
+
resetPassword: async (token, newPassword, options) => {
|
|
98
162
|
return this.request("POST", "/v1/auth/reset-password", {
|
|
99
|
-
body: { token, new_password: newPassword }
|
|
163
|
+
body: { token, new_password: newPassword },
|
|
164
|
+
clientContext: options?.clientContext
|
|
100
165
|
});
|
|
101
166
|
},
|
|
102
167
|
/**
|
|
@@ -809,6 +874,7 @@ function createAuthRoutes(config = {}) {
|
|
|
809
874
|
const path = params?.scalemule?.join("/") || "";
|
|
810
875
|
try {
|
|
811
876
|
const body = await request.json().catch(() => ({}));
|
|
877
|
+
const clientContext = extractClientContext(request);
|
|
812
878
|
switch (path) {
|
|
813
879
|
// ==================== Register ====================
|
|
814
880
|
case "register": {
|
|
@@ -818,7 +884,7 @@ function createAuthRoutes(config = {}) {
|
|
|
818
884
|
}
|
|
819
885
|
let registeredUser;
|
|
820
886
|
try {
|
|
821
|
-
registeredUser = await sm.auth.register({ email, password, full_name, username, phone });
|
|
887
|
+
registeredUser = await sm.auth.register({ email, password, full_name, username, phone }, { clientContext });
|
|
822
888
|
} catch (err) {
|
|
823
889
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
824
890
|
return errorResponse(
|
|
@@ -830,7 +896,13 @@ function createAuthRoutes(config = {}) {
|
|
|
830
896
|
if (config.onRegister) {
|
|
831
897
|
await config.onRegister({ id: registeredUser.id, email: registeredUser.email });
|
|
832
898
|
}
|
|
833
|
-
|
|
899
|
+
let loginData;
|
|
900
|
+
try {
|
|
901
|
+
loginData = await sm.auth.login({ email, password }, { clientContext });
|
|
902
|
+
} catch {
|
|
903
|
+
return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
|
|
904
|
+
}
|
|
905
|
+
return withSession(loginData, { user: registeredUser, sessionToken: loginData.session_token, userId: registeredUser.id }, cookieOptions);
|
|
834
906
|
}
|
|
835
907
|
// ==================== Login ====================
|
|
836
908
|
case "login": {
|
|
@@ -840,7 +912,7 @@ function createAuthRoutes(config = {}) {
|
|
|
840
912
|
}
|
|
841
913
|
let loginData;
|
|
842
914
|
try {
|
|
843
|
-
loginData = await sm.auth.login({ email, password, remember_me });
|
|
915
|
+
loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
|
|
844
916
|
} catch (err) {
|
|
845
917
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
846
918
|
const errorCode = apiErr?.code || "LOGIN_FAILED";
|
|
@@ -861,7 +933,7 @@ function createAuthRoutes(config = {}) {
|
|
|
861
933
|
email: loginData.user.email
|
|
862
934
|
});
|
|
863
935
|
}
|
|
864
|
-
return withSession(loginData, { user: loginData.user }, cookieOptions);
|
|
936
|
+
return withSession(loginData, { user: loginData.user, sessionToken: loginData.session_token, userId: loginData.user.id }, cookieOptions);
|
|
865
937
|
}
|
|
866
938
|
// ==================== Logout ====================
|
|
867
939
|
case "logout": {
|
|
@@ -880,7 +952,7 @@ function createAuthRoutes(config = {}) {
|
|
|
880
952
|
if (!email) {
|
|
881
953
|
return errorResponse("VALIDATION_ERROR", "Email required", 400);
|
|
882
954
|
}
|
|
883
|
-
const result = await sm.auth.forgotPassword(email);
|
|
955
|
+
const result = await sm.auth.forgotPassword(email, { clientContext });
|
|
884
956
|
return successResponse({ message: "If an account exists, a reset email has been sent" });
|
|
885
957
|
}
|
|
886
958
|
// ==================== Reset Password ====================
|
|
@@ -890,7 +962,7 @@ function createAuthRoutes(config = {}) {
|
|
|
890
962
|
return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
|
|
891
963
|
}
|
|
892
964
|
try {
|
|
893
|
-
await sm.auth.resetPassword(token, new_password);
|
|
965
|
+
await sm.auth.resetPassword(token, new_password, { clientContext });
|
|
894
966
|
} catch (err) {
|
|
895
967
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
896
968
|
return errorResponse(
|
package/dist/server/auth.mjs
CHANGED
|
@@ -12,6 +12,70 @@ var ScaleMuleApiError = class extends Error {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
// src/server/context.ts
|
|
15
|
+
function validateIP(ip) {
|
|
16
|
+
if (!ip) return void 0;
|
|
17
|
+
const trimmed = ip.trim();
|
|
18
|
+
if (!trimmed) return void 0;
|
|
19
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
20
|
+
const ipv6Regex = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,7}:$|^(?:[0-9a-fA-F]{1,4}:){0,6}::(?:[0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}$/;
|
|
21
|
+
const ipv4MappedRegex = /^::ffff:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i;
|
|
22
|
+
if (ipv4Regex.test(trimmed) || ipv6Regex.test(trimmed) || ipv4MappedRegex.test(trimmed)) {
|
|
23
|
+
return trimmed;
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
function extractClientContext(request) {
|
|
28
|
+
const headers = request.headers;
|
|
29
|
+
let ip;
|
|
30
|
+
const cfConnectingIp = headers.get("cf-connecting-ip");
|
|
31
|
+
if (cfConnectingIp) {
|
|
32
|
+
ip = validateIP(cfConnectingIp);
|
|
33
|
+
}
|
|
34
|
+
if (!ip) {
|
|
35
|
+
const doConnectingIp = headers.get("do-connecting-ip");
|
|
36
|
+
if (doConnectingIp) {
|
|
37
|
+
ip = validateIP(doConnectingIp);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!ip) {
|
|
41
|
+
const realIp = headers.get("x-real-ip");
|
|
42
|
+
if (realIp) {
|
|
43
|
+
ip = validateIP(realIp);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!ip) {
|
|
47
|
+
const forwardedFor = headers.get("x-forwarded-for");
|
|
48
|
+
if (forwardedFor) {
|
|
49
|
+
const firstIp = forwardedFor.split(",")[0]?.trim();
|
|
50
|
+
ip = validateIP(firstIp);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!ip) {
|
|
54
|
+
const vercelForwarded = headers.get("x-vercel-forwarded-for");
|
|
55
|
+
if (vercelForwarded) {
|
|
56
|
+
const firstIp = vercelForwarded.split(",")[0]?.trim();
|
|
57
|
+
ip = validateIP(firstIp);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!ip) {
|
|
61
|
+
const trueClientIp = headers.get("true-client-ip");
|
|
62
|
+
if (trueClientIp) {
|
|
63
|
+
ip = validateIP(trueClientIp);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!ip && request.ip) {
|
|
67
|
+
ip = validateIP(request.ip);
|
|
68
|
+
}
|
|
69
|
+
const userAgent = headers.get("user-agent") || void 0;
|
|
70
|
+
const deviceFingerprint = headers.get("x-device-fingerprint") || void 0;
|
|
71
|
+
const referrer = headers.get("referer") || void 0;
|
|
72
|
+
return {
|
|
73
|
+
ip,
|
|
74
|
+
userAgent,
|
|
75
|
+
deviceFingerprint,
|
|
76
|
+
referrer
|
|
77
|
+
};
|
|
78
|
+
}
|
|
15
79
|
function buildClientContextHeaders(context) {
|
|
16
80
|
const headers = {};
|
|
17
81
|
if (!context) {
|
|
@@ -52,14 +116,14 @@ var ScaleMuleServer = class {
|
|
|
52
116
|
/**
|
|
53
117
|
* Register a new user
|
|
54
118
|
*/
|
|
55
|
-
register: async (data) => {
|
|
56
|
-
return this.request("POST", "/v1/auth/register", { body: data });
|
|
119
|
+
register: async (data, options) => {
|
|
120
|
+
return this.request("POST", "/v1/auth/register", { body: data, clientContext: options?.clientContext });
|
|
57
121
|
},
|
|
58
122
|
/**
|
|
59
123
|
* Login user - returns session token (store in HTTP-only cookie)
|
|
60
124
|
*/
|
|
61
|
-
login: async (data) => {
|
|
62
|
-
return this.request("POST", "/v1/auth/login", { body: data });
|
|
125
|
+
login: async (data, options) => {
|
|
126
|
+
return this.request("POST", "/v1/auth/login", { body: data, clientContext: options?.clientContext });
|
|
63
127
|
},
|
|
64
128
|
/**
|
|
65
129
|
* Logout user
|
|
@@ -86,15 +150,16 @@ var ScaleMuleServer = class {
|
|
|
86
150
|
/**
|
|
87
151
|
* Request password reset email
|
|
88
152
|
*/
|
|
89
|
-
forgotPassword: async (email) => {
|
|
90
|
-
return this.request("POST", "/v1/auth/forgot-password", { body: { email } });
|
|
153
|
+
forgotPassword: async (email, options) => {
|
|
154
|
+
return this.request("POST", "/v1/auth/forgot-password", { body: { email }, clientContext: options?.clientContext });
|
|
91
155
|
},
|
|
92
156
|
/**
|
|
93
157
|
* Reset password with token
|
|
94
158
|
*/
|
|
95
|
-
resetPassword: async (token, newPassword) => {
|
|
159
|
+
resetPassword: async (token, newPassword, options) => {
|
|
96
160
|
return this.request("POST", "/v1/auth/reset-password", {
|
|
97
|
-
body: { token, new_password: newPassword }
|
|
161
|
+
body: { token, new_password: newPassword },
|
|
162
|
+
clientContext: options?.clientContext
|
|
98
163
|
});
|
|
99
164
|
},
|
|
100
165
|
/**
|
|
@@ -807,6 +872,7 @@ function createAuthRoutes(config = {}) {
|
|
|
807
872
|
const path = params?.scalemule?.join("/") || "";
|
|
808
873
|
try {
|
|
809
874
|
const body = await request.json().catch(() => ({}));
|
|
875
|
+
const clientContext = extractClientContext(request);
|
|
810
876
|
switch (path) {
|
|
811
877
|
// ==================== Register ====================
|
|
812
878
|
case "register": {
|
|
@@ -816,7 +882,7 @@ function createAuthRoutes(config = {}) {
|
|
|
816
882
|
}
|
|
817
883
|
let registeredUser;
|
|
818
884
|
try {
|
|
819
|
-
registeredUser = await sm.auth.register({ email, password, full_name, username, phone });
|
|
885
|
+
registeredUser = await sm.auth.register({ email, password, full_name, username, phone }, { clientContext });
|
|
820
886
|
} catch (err) {
|
|
821
887
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
822
888
|
return errorResponse(
|
|
@@ -828,7 +894,13 @@ function createAuthRoutes(config = {}) {
|
|
|
828
894
|
if (config.onRegister) {
|
|
829
895
|
await config.onRegister({ id: registeredUser.id, email: registeredUser.email });
|
|
830
896
|
}
|
|
831
|
-
|
|
897
|
+
let loginData;
|
|
898
|
+
try {
|
|
899
|
+
loginData = await sm.auth.login({ email, password }, { clientContext });
|
|
900
|
+
} catch {
|
|
901
|
+
return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
|
|
902
|
+
}
|
|
903
|
+
return withSession(loginData, { user: registeredUser, sessionToken: loginData.session_token, userId: registeredUser.id }, cookieOptions);
|
|
832
904
|
}
|
|
833
905
|
// ==================== Login ====================
|
|
834
906
|
case "login": {
|
|
@@ -838,7 +910,7 @@ function createAuthRoutes(config = {}) {
|
|
|
838
910
|
}
|
|
839
911
|
let loginData;
|
|
840
912
|
try {
|
|
841
|
-
loginData = await sm.auth.login({ email, password, remember_me });
|
|
913
|
+
loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
|
|
842
914
|
} catch (err) {
|
|
843
915
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
844
916
|
const errorCode = apiErr?.code || "LOGIN_FAILED";
|
|
@@ -859,7 +931,7 @@ function createAuthRoutes(config = {}) {
|
|
|
859
931
|
email: loginData.user.email
|
|
860
932
|
});
|
|
861
933
|
}
|
|
862
|
-
return withSession(loginData, { user: loginData.user }, cookieOptions);
|
|
934
|
+
return withSession(loginData, { user: loginData.user, sessionToken: loginData.session_token, userId: loginData.user.id }, cookieOptions);
|
|
863
935
|
}
|
|
864
936
|
// ==================== Logout ====================
|
|
865
937
|
case "logout": {
|
|
@@ -878,7 +950,7 @@ function createAuthRoutes(config = {}) {
|
|
|
878
950
|
if (!email) {
|
|
879
951
|
return errorResponse("VALIDATION_ERROR", "Email required", 400);
|
|
880
952
|
}
|
|
881
|
-
const result = await sm.auth.forgotPassword(email);
|
|
953
|
+
const result = await sm.auth.forgotPassword(email, { clientContext });
|
|
882
954
|
return successResponse({ message: "If an account exists, a reset email has been sent" });
|
|
883
955
|
}
|
|
884
956
|
// ==================== Reset Password ====================
|
|
@@ -888,7 +960,7 @@ function createAuthRoutes(config = {}) {
|
|
|
888
960
|
return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
|
|
889
961
|
}
|
|
890
962
|
try {
|
|
891
|
-
await sm.auth.resetPassword(token, new_password);
|
|
963
|
+
await sm.auth.resetPassword(token, new_password, { clientContext });
|
|
892
964
|
} catch (err) {
|
|
893
965
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
894
966
|
return errorResponse(
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, d as VideoFailedEvent, V as VideoReadyEvent, f as VideoTranscodedEvent, e as VideoUploadedEvent, W as WebhookEvent, g as WebhookRoutesConfig, c as createServerClient, h as createWebhookHandler, b as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, v as verifyWebhookSignature } from '../webhook-handler-
|
|
3
|
-
import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-BzBvYbZU.mjs';
|
|
2
|
+
export { a as ScaleMuleServer, d as VideoFailedEvent, V as VideoReadyEvent, f as VideoTranscodedEvent, e as VideoUploadedEvent, W as WebhookEvent, g as WebhookRoutesConfig, c as createServerClient, h as createWebhookHandler, b as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, v as verifyWebhookSignature } from '../webhook-handler-BzBvYbZU.mjs';
|
|
3
|
+
import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-jomBa89d.mjs';
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, d as VideoFailedEvent, V as VideoReadyEvent, f as VideoTranscodedEvent, e as VideoUploadedEvent, W as WebhookEvent, g as WebhookRoutesConfig, c as createServerClient, h as createWebhookHandler, b as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, v as verifyWebhookSignature } from '../webhook-handler-
|
|
3
|
-
import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-tcJtRpkE.js';
|
|
2
|
+
export { a as ScaleMuleServer, d as VideoFailedEvent, V as VideoReadyEvent, f as VideoTranscodedEvent, e as VideoUploadedEvent, W as WebhookEvent, g as WebhookRoutesConfig, c as createServerClient, h as createWebhookHandler, b as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, v as verifyWebhookSignature } from '../webhook-handler-tcJtRpkE.js';
|
|
3
|
+
import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-jomBa89d.js';
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/server/index.js
CHANGED
|
@@ -178,14 +178,14 @@ var ScaleMuleServer = class {
|
|
|
178
178
|
/**
|
|
179
179
|
* Register a new user
|
|
180
180
|
*/
|
|
181
|
-
register: async (data) => {
|
|
182
|
-
return this.request("POST", "/v1/auth/register", { body: data });
|
|
181
|
+
register: async (data, options) => {
|
|
182
|
+
return this.request("POST", "/v1/auth/register", { body: data, clientContext: options?.clientContext });
|
|
183
183
|
},
|
|
184
184
|
/**
|
|
185
185
|
* Login user - returns session token (store in HTTP-only cookie)
|
|
186
186
|
*/
|
|
187
|
-
login: async (data) => {
|
|
188
|
-
return this.request("POST", "/v1/auth/login", { body: data });
|
|
187
|
+
login: async (data, options) => {
|
|
188
|
+
return this.request("POST", "/v1/auth/login", { body: data, clientContext: options?.clientContext });
|
|
189
189
|
},
|
|
190
190
|
/**
|
|
191
191
|
* Logout user
|
|
@@ -212,15 +212,16 @@ var ScaleMuleServer = class {
|
|
|
212
212
|
/**
|
|
213
213
|
* Request password reset email
|
|
214
214
|
*/
|
|
215
|
-
forgotPassword: async (email) => {
|
|
216
|
-
return this.request("POST", "/v1/auth/forgot-password", { body: { email } });
|
|
215
|
+
forgotPassword: async (email, options) => {
|
|
216
|
+
return this.request("POST", "/v1/auth/forgot-password", { body: { email }, clientContext: options?.clientContext });
|
|
217
217
|
},
|
|
218
218
|
/**
|
|
219
219
|
* Reset password with token
|
|
220
220
|
*/
|
|
221
|
-
resetPassword: async (token, newPassword) => {
|
|
221
|
+
resetPassword: async (token, newPassword, options) => {
|
|
222
222
|
return this.request("POST", "/v1/auth/reset-password", {
|
|
223
|
-
body: { token, new_password: newPassword }
|
|
223
|
+
body: { token, new_password: newPassword },
|
|
224
|
+
clientContext: options?.clientContext
|
|
224
225
|
});
|
|
225
226
|
},
|
|
226
227
|
/**
|
|
@@ -1026,6 +1027,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1026
1027
|
const path = params?.scalemule?.join("/") || "";
|
|
1027
1028
|
try {
|
|
1028
1029
|
const body = await request.json().catch(() => ({}));
|
|
1030
|
+
const clientContext = extractClientContext(request);
|
|
1029
1031
|
switch (path) {
|
|
1030
1032
|
// ==================== Register ====================
|
|
1031
1033
|
case "register": {
|
|
@@ -1035,7 +1037,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1035
1037
|
}
|
|
1036
1038
|
let registeredUser;
|
|
1037
1039
|
try {
|
|
1038
|
-
registeredUser = await sm.auth.register({ email, password, full_name, username, phone });
|
|
1040
|
+
registeredUser = await sm.auth.register({ email, password, full_name, username, phone }, { clientContext });
|
|
1039
1041
|
} catch (err) {
|
|
1040
1042
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
1041
1043
|
return errorResponse(
|
|
@@ -1047,7 +1049,13 @@ function createAuthRoutes(config = {}) {
|
|
|
1047
1049
|
if (config.onRegister) {
|
|
1048
1050
|
await config.onRegister({ id: registeredUser.id, email: registeredUser.email });
|
|
1049
1051
|
}
|
|
1050
|
-
|
|
1052
|
+
let loginData;
|
|
1053
|
+
try {
|
|
1054
|
+
loginData = await sm.auth.login({ email, password }, { clientContext });
|
|
1055
|
+
} catch {
|
|
1056
|
+
return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
|
|
1057
|
+
}
|
|
1058
|
+
return withSession(loginData, { user: registeredUser, sessionToken: loginData.session_token, userId: registeredUser.id }, cookieOptions);
|
|
1051
1059
|
}
|
|
1052
1060
|
// ==================== Login ====================
|
|
1053
1061
|
case "login": {
|
|
@@ -1057,7 +1065,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1057
1065
|
}
|
|
1058
1066
|
let loginData;
|
|
1059
1067
|
try {
|
|
1060
|
-
loginData = await sm.auth.login({ email, password, remember_me });
|
|
1068
|
+
loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
|
|
1061
1069
|
} catch (err) {
|
|
1062
1070
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
1063
1071
|
const errorCode = apiErr?.code || "LOGIN_FAILED";
|
|
@@ -1078,7 +1086,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1078
1086
|
email: loginData.user.email
|
|
1079
1087
|
});
|
|
1080
1088
|
}
|
|
1081
|
-
return withSession(loginData, { user: loginData.user }, cookieOptions);
|
|
1089
|
+
return withSession(loginData, { user: loginData.user, sessionToken: loginData.session_token, userId: loginData.user.id }, cookieOptions);
|
|
1082
1090
|
}
|
|
1083
1091
|
// ==================== Logout ====================
|
|
1084
1092
|
case "logout": {
|
|
@@ -1097,7 +1105,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1097
1105
|
if (!email) {
|
|
1098
1106
|
return errorResponse("VALIDATION_ERROR", "Email required", 400);
|
|
1099
1107
|
}
|
|
1100
|
-
const result = await sm.auth.forgotPassword(email);
|
|
1108
|
+
const result = await sm.auth.forgotPassword(email, { clientContext });
|
|
1101
1109
|
return successResponse({ message: "If an account exists, a reset email has been sent" });
|
|
1102
1110
|
}
|
|
1103
1111
|
// ==================== Reset Password ====================
|
|
@@ -1107,7 +1115,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1107
1115
|
return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
|
|
1108
1116
|
}
|
|
1109
1117
|
try {
|
|
1110
|
-
await sm.auth.resetPassword(token, new_password);
|
|
1118
|
+
await sm.auth.resetPassword(token, new_password, { clientContext });
|
|
1111
1119
|
} catch (err) {
|
|
1112
1120
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
1113
1121
|
return errorResponse(
|
package/dist/server/index.mjs
CHANGED
|
@@ -176,14 +176,14 @@ var ScaleMuleServer = class {
|
|
|
176
176
|
/**
|
|
177
177
|
* Register a new user
|
|
178
178
|
*/
|
|
179
|
-
register: async (data) => {
|
|
180
|
-
return this.request("POST", "/v1/auth/register", { body: data });
|
|
179
|
+
register: async (data, options) => {
|
|
180
|
+
return this.request("POST", "/v1/auth/register", { body: data, clientContext: options?.clientContext });
|
|
181
181
|
},
|
|
182
182
|
/**
|
|
183
183
|
* Login user - returns session token (store in HTTP-only cookie)
|
|
184
184
|
*/
|
|
185
|
-
login: async (data) => {
|
|
186
|
-
return this.request("POST", "/v1/auth/login", { body: data });
|
|
185
|
+
login: async (data, options) => {
|
|
186
|
+
return this.request("POST", "/v1/auth/login", { body: data, clientContext: options?.clientContext });
|
|
187
187
|
},
|
|
188
188
|
/**
|
|
189
189
|
* Logout user
|
|
@@ -210,15 +210,16 @@ var ScaleMuleServer = class {
|
|
|
210
210
|
/**
|
|
211
211
|
* Request password reset email
|
|
212
212
|
*/
|
|
213
|
-
forgotPassword: async (email) => {
|
|
214
|
-
return this.request("POST", "/v1/auth/forgot-password", { body: { email } });
|
|
213
|
+
forgotPassword: async (email, options) => {
|
|
214
|
+
return this.request("POST", "/v1/auth/forgot-password", { body: { email }, clientContext: options?.clientContext });
|
|
215
215
|
},
|
|
216
216
|
/**
|
|
217
217
|
* Reset password with token
|
|
218
218
|
*/
|
|
219
|
-
resetPassword: async (token, newPassword) => {
|
|
219
|
+
resetPassword: async (token, newPassword, options) => {
|
|
220
220
|
return this.request("POST", "/v1/auth/reset-password", {
|
|
221
|
-
body: { token, new_password: newPassword }
|
|
221
|
+
body: { token, new_password: newPassword },
|
|
222
|
+
clientContext: options?.clientContext
|
|
222
223
|
});
|
|
223
224
|
},
|
|
224
225
|
/**
|
|
@@ -1024,6 +1025,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1024
1025
|
const path = params?.scalemule?.join("/") || "";
|
|
1025
1026
|
try {
|
|
1026
1027
|
const body = await request.json().catch(() => ({}));
|
|
1028
|
+
const clientContext = extractClientContext(request);
|
|
1027
1029
|
switch (path) {
|
|
1028
1030
|
// ==================== Register ====================
|
|
1029
1031
|
case "register": {
|
|
@@ -1033,7 +1035,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1033
1035
|
}
|
|
1034
1036
|
let registeredUser;
|
|
1035
1037
|
try {
|
|
1036
|
-
registeredUser = await sm.auth.register({ email, password, full_name, username, phone });
|
|
1038
|
+
registeredUser = await sm.auth.register({ email, password, full_name, username, phone }, { clientContext });
|
|
1037
1039
|
} catch (err) {
|
|
1038
1040
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
1039
1041
|
return errorResponse(
|
|
@@ -1045,7 +1047,13 @@ function createAuthRoutes(config = {}) {
|
|
|
1045
1047
|
if (config.onRegister) {
|
|
1046
1048
|
await config.onRegister({ id: registeredUser.id, email: registeredUser.email });
|
|
1047
1049
|
}
|
|
1048
|
-
|
|
1050
|
+
let loginData;
|
|
1051
|
+
try {
|
|
1052
|
+
loginData = await sm.auth.login({ email, password }, { clientContext });
|
|
1053
|
+
} catch {
|
|
1054
|
+
return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
|
|
1055
|
+
}
|
|
1056
|
+
return withSession(loginData, { user: registeredUser, sessionToken: loginData.session_token, userId: registeredUser.id }, cookieOptions);
|
|
1049
1057
|
}
|
|
1050
1058
|
// ==================== Login ====================
|
|
1051
1059
|
case "login": {
|
|
@@ -1055,7 +1063,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1055
1063
|
}
|
|
1056
1064
|
let loginData;
|
|
1057
1065
|
try {
|
|
1058
|
-
loginData = await sm.auth.login({ email, password, remember_me });
|
|
1066
|
+
loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
|
|
1059
1067
|
} catch (err) {
|
|
1060
1068
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
1061
1069
|
const errorCode = apiErr?.code || "LOGIN_FAILED";
|
|
@@ -1076,7 +1084,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1076
1084
|
email: loginData.user.email
|
|
1077
1085
|
});
|
|
1078
1086
|
}
|
|
1079
|
-
return withSession(loginData, { user: loginData.user }, cookieOptions);
|
|
1087
|
+
return withSession(loginData, { user: loginData.user, sessionToken: loginData.session_token, userId: loginData.user.id }, cookieOptions);
|
|
1080
1088
|
}
|
|
1081
1089
|
// ==================== Logout ====================
|
|
1082
1090
|
case "logout": {
|
|
@@ -1095,7 +1103,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1095
1103
|
if (!email) {
|
|
1096
1104
|
return errorResponse("VALIDATION_ERROR", "Email required", 400);
|
|
1097
1105
|
}
|
|
1098
|
-
const result = await sm.auth.forgotPassword(email);
|
|
1106
|
+
const result = await sm.auth.forgotPassword(email, { clientContext });
|
|
1099
1107
|
return successResponse({ message: "If an account exists, a reset email has been sent" });
|
|
1100
1108
|
}
|
|
1101
1109
|
// ==================== Reset Password ====================
|
|
@@ -1105,7 +1113,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1105
1113
|
return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
|
|
1106
1114
|
}
|
|
1107
1115
|
try {
|
|
1108
|
-
await sm.auth.resetPassword(token, new_password);
|
|
1116
|
+
await sm.auth.resetPassword(token, new_password, { clientContext });
|
|
1109
1117
|
} catch (err) {
|
|
1110
1118
|
const apiErr = err instanceof ScaleMuleApiError ? err : null;
|
|
1111
1119
|
return errorResponse(
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { h as createWebhookHandler } from '../webhook-handler-
|
|
2
|
-
import '../index-
|
|
1
|
+
export { h as createWebhookHandler } from '../webhook-handler-BzBvYbZU.mjs';
|
|
2
|
+
import '../index-jomBa89d.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { h as createWebhookHandler } from '../webhook-handler-
|
|
2
|
-
import '../index-
|
|
1
|
+
export { h as createWebhookHandler } from '../webhook-handler-tcJtRpkE.js';
|
|
2
|
+
import '../index-jomBa89d.js';
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { U as User, N as StorageFile, A as ApiError } from './index-
|
|
3
|
+
import { U as User, N as StorageFile, A as ApiError } from './index-jomBa89d.mjs';
|
|
4
4
|
|
|
5
5
|
interface MockUserOptions {
|
|
6
6
|
id?: string;
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { U as User, N as StorageFile, A as ApiError } from './index-
|
|
3
|
+
import { U as User, N as StorageFile, A as ApiError } from './index-jomBa89d.js';
|
|
4
4
|
|
|
5
5
|
interface MockUserOptions {
|
|
6
6
|
id?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RegisterRequest, U as User, l as LoginRequest, L as LoginResponse, c as ListFilesParams, T as ListFilesResponse, N as StorageFile,
|
|
1
|
+
import { R as RegisterRequest, $ as ClientContext, U as User, l as LoginRequest, L as LoginResponse, c as ListFilesParams, T as ListFilesResponse, N as StorageFile, W as UploadResponse } from './index-jomBa89d.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Server-Side ScaleMule Client
|
|
@@ -39,11 +39,15 @@ declare class ScaleMuleServer {
|
|
|
39
39
|
/**
|
|
40
40
|
* Register a new user
|
|
41
41
|
*/
|
|
42
|
-
register: (data: RegisterRequest
|
|
42
|
+
register: (data: RegisterRequest, options?: {
|
|
43
|
+
clientContext?: ClientContext;
|
|
44
|
+
}) => Promise<User>;
|
|
43
45
|
/**
|
|
44
46
|
* Login user - returns session token (store in HTTP-only cookie)
|
|
45
47
|
*/
|
|
46
|
-
login: (data: LoginRequest
|
|
48
|
+
login: (data: LoginRequest, options?: {
|
|
49
|
+
clientContext?: ClientContext;
|
|
50
|
+
}) => Promise<LoginResponse>;
|
|
47
51
|
/**
|
|
48
52
|
* Logout user
|
|
49
53
|
*/
|
|
@@ -62,13 +66,17 @@ declare class ScaleMuleServer {
|
|
|
62
66
|
/**
|
|
63
67
|
* Request password reset email
|
|
64
68
|
*/
|
|
65
|
-
forgotPassword: (email: string
|
|
69
|
+
forgotPassword: (email: string, options?: {
|
|
70
|
+
clientContext?: ClientContext;
|
|
71
|
+
}) => Promise<{
|
|
66
72
|
message: string;
|
|
67
73
|
}>;
|
|
68
74
|
/**
|
|
69
75
|
* Reset password with token
|
|
70
76
|
*/
|
|
71
|
-
resetPassword: (token: string, newPassword: string
|
|
77
|
+
resetPassword: (token: string, newPassword: string, options?: {
|
|
78
|
+
clientContext?: ClientContext;
|
|
79
|
+
}) => Promise<{
|
|
72
80
|
message: string;
|
|
73
81
|
}>;
|
|
74
82
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RegisterRequest, U as User, l as LoginRequest, L as LoginResponse, c as ListFilesParams, T as ListFilesResponse, N as StorageFile,
|
|
1
|
+
import { R as RegisterRequest, $ as ClientContext, U as User, l as LoginRequest, L as LoginResponse, c as ListFilesParams, T as ListFilesResponse, N as StorageFile, W as UploadResponse } from './index-jomBa89d.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Server-Side ScaleMule Client
|
|
@@ -39,11 +39,15 @@ declare class ScaleMuleServer {
|
|
|
39
39
|
/**
|
|
40
40
|
* Register a new user
|
|
41
41
|
*/
|
|
42
|
-
register: (data: RegisterRequest
|
|
42
|
+
register: (data: RegisterRequest, options?: {
|
|
43
|
+
clientContext?: ClientContext;
|
|
44
|
+
}) => Promise<User>;
|
|
43
45
|
/**
|
|
44
46
|
* Login user - returns session token (store in HTTP-only cookie)
|
|
45
47
|
*/
|
|
46
|
-
login: (data: LoginRequest
|
|
48
|
+
login: (data: LoginRequest, options?: {
|
|
49
|
+
clientContext?: ClientContext;
|
|
50
|
+
}) => Promise<LoginResponse>;
|
|
47
51
|
/**
|
|
48
52
|
* Logout user
|
|
49
53
|
*/
|
|
@@ -62,13 +66,17 @@ declare class ScaleMuleServer {
|
|
|
62
66
|
/**
|
|
63
67
|
* Request password reset email
|
|
64
68
|
*/
|
|
65
|
-
forgotPassword: (email: string
|
|
69
|
+
forgotPassword: (email: string, options?: {
|
|
70
|
+
clientContext?: ClientContext;
|
|
71
|
+
}) => Promise<{
|
|
66
72
|
message: string;
|
|
67
73
|
}>;
|
|
68
74
|
/**
|
|
69
75
|
* Reset password with token
|
|
70
76
|
*/
|
|
71
|
-
resetPassword: (token: string, newPassword: string
|
|
77
|
+
resetPassword: (token: string, newPassword: string, options?: {
|
|
78
|
+
clientContext?: ClientContext;
|
|
79
|
+
}) => Promise<{
|
|
72
80
|
message: string;
|
|
73
81
|
}>;
|
|
74
82
|
/**
|
package/package.json
CHANGED