@scalemule/nextjs 0.0.7 → 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.
@@ -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(
@@ -832,7 +898,7 @@ function createAuthRoutes(config = {}) {
832
898
  }
833
899
  let loginData;
834
900
  try {
835
- loginData = await sm.auth.login({ email, password });
901
+ loginData = await sm.auth.login({ email, password }, { clientContext });
836
902
  } catch {
837
903
  return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
838
904
  }
@@ -846,7 +912,7 @@ function createAuthRoutes(config = {}) {
846
912
  }
847
913
  let loginData;
848
914
  try {
849
- loginData = await sm.auth.login({ email, password, remember_me });
915
+ loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
850
916
  } catch (err) {
851
917
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
852
918
  const errorCode = apiErr?.code || "LOGIN_FAILED";
@@ -886,7 +952,7 @@ function createAuthRoutes(config = {}) {
886
952
  if (!email) {
887
953
  return errorResponse("VALIDATION_ERROR", "Email required", 400);
888
954
  }
889
- const result = await sm.auth.forgotPassword(email);
955
+ const result = await sm.auth.forgotPassword(email, { clientContext });
890
956
  return successResponse({ message: "If an account exists, a reset email has been sent" });
891
957
  }
892
958
  // ==================== Reset Password ====================
@@ -896,7 +962,7 @@ function createAuthRoutes(config = {}) {
896
962
  return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
897
963
  }
898
964
  try {
899
- await sm.auth.resetPassword(token, new_password);
965
+ await sm.auth.resetPassword(token, new_password, { clientContext });
900
966
  } catch (err) {
901
967
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
902
968
  return errorResponse(
@@ -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(
@@ -830,7 +896,7 @@ function createAuthRoutes(config = {}) {
830
896
  }
831
897
  let loginData;
832
898
  try {
833
- loginData = await sm.auth.login({ email, password });
899
+ loginData = await sm.auth.login({ email, password }, { clientContext });
834
900
  } catch {
835
901
  return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
836
902
  }
@@ -844,7 +910,7 @@ function createAuthRoutes(config = {}) {
844
910
  }
845
911
  let loginData;
846
912
  try {
847
- loginData = await sm.auth.login({ email, password, remember_me });
913
+ loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
848
914
  } catch (err) {
849
915
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
850
916
  const errorCode = apiErr?.code || "LOGIN_FAILED";
@@ -884,7 +950,7 @@ function createAuthRoutes(config = {}) {
884
950
  if (!email) {
885
951
  return errorResponse("VALIDATION_ERROR", "Email required", 400);
886
952
  }
887
- const result = await sm.auth.forgotPassword(email);
953
+ const result = await sm.auth.forgotPassword(email, { clientContext });
888
954
  return successResponse({ message: "If an account exists, a reset email has been sent" });
889
955
  }
890
956
  // ==================== Reset Password ====================
@@ -894,7 +960,7 @@ function createAuthRoutes(config = {}) {
894
960
  return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
895
961
  }
896
962
  try {
897
- await sm.auth.resetPassword(token, new_password);
963
+ await sm.auth.resetPassword(token, new_password, { clientContext });
898
964
  } catch (err) {
899
965
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
900
966
  return errorResponse(
@@ -1,5 +1,5 @@
1
- import { S as ServerConfig } from '../webhook-handler-B_S2RgMO.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-B_S2RgMO.mjs';
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
3
  import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-jomBa89d.mjs';
4
4
  import { NextRequest, NextResponse } from 'next/server';
5
5
 
@@ -1,5 +1,5 @@
1
- import { S as ServerConfig } from '../webhook-handler-BKhYMJ9A.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-BKhYMJ9A.js';
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
3
  import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-jomBa89d.js';
4
4
  import { NextRequest, NextResponse } from 'next/server';
5
5
 
@@ -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(
@@ -1049,7 +1051,7 @@ function createAuthRoutes(config = {}) {
1049
1051
  }
1050
1052
  let loginData;
1051
1053
  try {
1052
- loginData = await sm.auth.login({ email, password });
1054
+ loginData = await sm.auth.login({ email, password }, { clientContext });
1053
1055
  } catch {
1054
1056
  return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
1055
1057
  }
@@ -1063,7 +1065,7 @@ function createAuthRoutes(config = {}) {
1063
1065
  }
1064
1066
  let loginData;
1065
1067
  try {
1066
- loginData = await sm.auth.login({ email, password, remember_me });
1068
+ loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
1067
1069
  } catch (err) {
1068
1070
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
1069
1071
  const errorCode = apiErr?.code || "LOGIN_FAILED";
@@ -1103,7 +1105,7 @@ function createAuthRoutes(config = {}) {
1103
1105
  if (!email) {
1104
1106
  return errorResponse("VALIDATION_ERROR", "Email required", 400);
1105
1107
  }
1106
- const result = await sm.auth.forgotPassword(email);
1108
+ const result = await sm.auth.forgotPassword(email, { clientContext });
1107
1109
  return successResponse({ message: "If an account exists, a reset email has been sent" });
1108
1110
  }
1109
1111
  // ==================== Reset Password ====================
@@ -1113,7 +1115,7 @@ function createAuthRoutes(config = {}) {
1113
1115
  return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
1114
1116
  }
1115
1117
  try {
1116
- await sm.auth.resetPassword(token, new_password);
1118
+ await sm.auth.resetPassword(token, new_password, { clientContext });
1117
1119
  } catch (err) {
1118
1120
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
1119
1121
  return errorResponse(
@@ -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(
@@ -1047,7 +1049,7 @@ function createAuthRoutes(config = {}) {
1047
1049
  }
1048
1050
  let loginData;
1049
1051
  try {
1050
- loginData = await sm.auth.login({ email, password });
1052
+ loginData = await sm.auth.login({ email, password }, { clientContext });
1051
1053
  } catch {
1052
1054
  return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
1053
1055
  }
@@ -1061,7 +1063,7 @@ function createAuthRoutes(config = {}) {
1061
1063
  }
1062
1064
  let loginData;
1063
1065
  try {
1064
- loginData = await sm.auth.login({ email, password, remember_me });
1066
+ loginData = await sm.auth.login({ email, password, remember_me }, { clientContext });
1065
1067
  } catch (err) {
1066
1068
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
1067
1069
  const errorCode = apiErr?.code || "LOGIN_FAILED";
@@ -1101,7 +1103,7 @@ function createAuthRoutes(config = {}) {
1101
1103
  if (!email) {
1102
1104
  return errorResponse("VALIDATION_ERROR", "Email required", 400);
1103
1105
  }
1104
- const result = await sm.auth.forgotPassword(email);
1106
+ const result = await sm.auth.forgotPassword(email, { clientContext });
1105
1107
  return successResponse({ message: "If an account exists, a reset email has been sent" });
1106
1108
  }
1107
1109
  // ==================== Reset Password ====================
@@ -1111,7 +1113,7 @@ function createAuthRoutes(config = {}) {
1111
1113
  return errorResponse("VALIDATION_ERROR", "Token and new password required", 400);
1112
1114
  }
1113
1115
  try {
1114
- await sm.auth.resetPassword(token, new_password);
1116
+ await sm.auth.resetPassword(token, new_password, { clientContext });
1115
1117
  } catch (err) {
1116
1118
  const apiErr = err instanceof ScaleMuleApiError ? err : null;
1117
1119
  return errorResponse(
@@ -1,2 +1,2 @@
1
- export { h as createWebhookHandler } from '../webhook-handler-B_S2RgMO.mjs';
1
+ export { h as createWebhookHandler } from '../webhook-handler-BzBvYbZU.mjs';
2
2
  import '../index-jomBa89d.mjs';
@@ -1,2 +1,2 @@
1
- export { h as createWebhookHandler } from '../webhook-handler-BKhYMJ9A.js';
1
+ export { h as createWebhookHandler } from '../webhook-handler-tcJtRpkE.js';
2
2
  import '../index-jomBa89d.js';
@@ -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, $ as ClientContext, W as UploadResponse } from './index-jomBa89d.mjs';
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) => Promise<User>;
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) => Promise<LoginResponse>;
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) => Promise<{
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) => Promise<{
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, $ as ClientContext, W as UploadResponse } from './index-jomBa89d.js';
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) => Promise<User>;
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) => Promise<LoginResponse>;
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) => Promise<{
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) => Promise<{
77
+ resetPassword: (token: string, newPassword: string, options?: {
78
+ clientContext?: ClientContext;
79
+ }) => Promise<{
72
80
  message: string;
73
81
  }>;
74
82
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",