@sanvika/auth 2.4.0 → 2.5.0

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/index.js CHANGED
@@ -18,10 +18,8 @@ function SanvikaAuthProvider({
18
18
  children,
19
19
  clientId,
20
20
  redirectUri,
21
- saUrl: saUrlProp,
22
21
  dashboardPath
23
22
  }) {
24
- const saBaseUrl = saUrlProp || S_AUTH_URL;
25
23
  const [user, setUser] = useState(null);
26
24
  const [accessToken, setToken] = useState(null);
27
25
  const [loading, setLoading] = useState(true);
@@ -106,7 +104,6 @@ function SanvikaAuthProvider({
106
104
  authFetch,
107
105
  clientId,
108
106
  redirectUri,
109
- saBaseUrl,
110
107
  dashboardPath
111
108
  };
112
109
  return /* @__PURE__ */ jsx(SanvikaAuthContext.Provider, { value, children });
package/dist/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // server.js
2
- var _saUrl = () => {
2
+ var _authUrl = () => {
3
3
  var _a;
4
- return typeof process !== "undefined" && ((_a = process.env) == null ? void 0 : _a.SA_URL) || "https://accounts.sanvikaproduction.com";
4
+ return typeof process !== "undefined" && ((_a = process.env) == null ? void 0 : _a.AUTH_URL) || "https://accounts.sanvikaproduction.com";
5
5
  };
6
6
  var _serviceKey = () => {
7
7
  var _a;
@@ -11,11 +11,11 @@ var _s2sHeaders = () => ({
11
11
  "Content-Type": "application/json",
12
12
  ..._serviceKey() ? { "x-service-key": _serviceKey() } : {}
13
13
  });
14
- async function verifySAToken(request) {
14
+ async function verifyAuthToken(request) {
15
15
  try {
16
16
  const auth = request.headers.get("authorization");
17
17
  if (!(auth == null ? void 0 : auth.startsWith("Bearer "))) return null;
18
- const res = await fetch(`${_saUrl()}/api/auth/verify-token`, {
18
+ const res = await fetch(`${_authUrl()}/api/auth/verify-token`, {
19
19
  method: "GET",
20
20
  headers: { Authorization: auth }
21
21
  });
@@ -26,14 +26,14 @@ async function verifySAToken(request) {
26
26
  return null;
27
27
  }
28
28
  }
29
- async function extractSAUid(request) {
30
- const payload = await verifySAToken(request);
29
+ async function extractAuthUid(request) {
30
+ const payload = await verifyAuthToken(request);
31
31
  return (payload == null ? void 0 : payload.sub) || null;
32
32
  }
33
- async function getUserFromSA(uid) {
33
+ async function getUserFromAuth(uid) {
34
34
  if (!uid) return null;
35
35
  try {
36
- const res = await fetch(`${_saUrl()}/api/user/profile?uid=${uid}`, {
36
+ const res = await fetch(`${_authUrl()}/api/user/profile?uid=${uid}`, {
37
37
  headers: _s2sHeaders(),
38
38
  signal: AbortSignal.timeout(5e3)
39
39
  });
@@ -44,10 +44,10 @@ async function getUserFromSA(uid) {
44
44
  return null;
45
45
  }
46
46
  }
47
- async function getUserLocationFromSA(uid) {
47
+ async function getUserLocationFromAuth(uid) {
48
48
  if (!uid) return null;
49
49
  try {
50
- const res = await fetch(`${_saUrl()}/api/location?uid=${uid}`, {
50
+ const res = await fetch(`${_authUrl()}/api/location?uid=${uid}`, {
51
51
  headers: _s2sHeaders(),
52
52
  signal: AbortSignal.timeout(5e3)
53
53
  });
@@ -58,7 +58,7 @@ async function getUserLocationFromSA(uid) {
58
58
  return null;
59
59
  }
60
60
  }
61
- async function getUserByMobileFromSA(mobile, authToken = "") {
61
+ async function getUserByMobileFromAuth(mobile, authToken = "") {
62
62
  var _a;
63
63
  if (!mobile) return null;
64
64
  try {
@@ -67,7 +67,7 @@ async function getUserByMobileFromSA(mobile, authToken = "") {
67
67
  ...authToken ? { Authorization: `Bearer ${authToken}` } : {}
68
68
  };
69
69
  const res = await fetch(
70
- `${_saUrl()}/api/admin/users?search=${encodeURIComponent(mobile)}&limit=1`,
70
+ `${_authUrl()}/api/admin/users?search=${encodeURIComponent(mobile)}&limit=1`,
71
71
  { headers, signal: AbortSignal.timeout(5e3) }
72
72
  );
73
73
  if (!res.ok) return null;
@@ -77,21 +77,21 @@ async function getUserByMobileFromSA(mobile, authToken = "") {
77
77
  return null;
78
78
  }
79
79
  }
80
- async function batchGetUsersFromSA(uids) {
80
+ async function batchGetUsersFromAuth(uids) {
81
81
  const results = /* @__PURE__ */ new Map();
82
82
  const batchSize = 10;
83
83
  for (let i = 0; i < uids.length; i += batchSize) {
84
84
  const batch = uids.slice(i, i + batchSize);
85
85
  await Promise.all(
86
86
  batch.map(async (uid) => {
87
- const user = await getUserFromSA(uid);
87
+ const user = await getUserFromAuth(uid);
88
88
  if (user) results.set(uid, user);
89
89
  })
90
90
  );
91
91
  }
92
92
  return results;
93
93
  }
94
- async function listUsersFromSA({ page = 1, limit = 20, search = "", authToken = "" } = {}) {
94
+ async function listUsersFromAuth({ page = 1, limit = 20, search = "", authToken = "" } = {}) {
95
95
  const empty = { users: [], pagination: { page, limit, total: 0, pages: 0 } };
96
96
  try {
97
97
  const params = new URLSearchParams({ page: String(page), limit: String(limit) });
@@ -100,7 +100,7 @@ async function listUsersFromSA({ page = 1, limit = 20, search = "", authToken =
100
100
  ..._s2sHeaders(),
101
101
  ...authToken ? { Authorization: `Bearer ${authToken}` } : {}
102
102
  };
103
- const res = await fetch(`${_saUrl()}/api/admin/users?${params}`, {
103
+ const res = await fetch(`${_authUrl()}/api/admin/users?${params}`, {
104
104
  headers,
105
105
  signal: AbortSignal.timeout(8e3)
106
106
  });
@@ -112,11 +112,11 @@ async function listUsersFromSA({ page = 1, limit = 20, search = "", authToken =
112
112
  }
113
113
  }
114
114
  export {
115
- batchGetUsersFromSA,
116
- extractSAUid,
117
- getUserByMobileFromSA,
118
- getUserFromSA,
119
- getUserLocationFromSA,
120
- listUsersFromSA,
121
- verifySAToken
115
+ batchGetUsersFromAuth,
116
+ extractAuthUid,
117
+ getUserByMobileFromAuth,
118
+ getUserFromAuth,
119
+ getUserLocationFromAuth,
120
+ listUsersFromAuth,
121
+ verifyAuthToken
122
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/auth",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Sanvika Auth SDK — React components/hooks + server-side token verification and user proxy",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",