@poly-x/next 0.1.0-alpha.14 → 0.1.0-alpha.15

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/server.cjs CHANGED
@@ -113,6 +113,24 @@ function collectForwardedDeviceHeaders(request) {
113
113
  if (clientIp) forwarded["x-forwarded-for"] = clientIp;
114
114
  return forwarded;
115
115
  }
116
+ /**
117
+ * Build the forwarded precise-location headers (`x-polyx-geo-*`) from the browser's login
118
+ * body (v6, FR-LOC-7). The browser captures a consented position client-side and posts it;
119
+ * the platform reads these on the token exchange. Only well-formed values are forwarded, and
120
+ * the consent state rides even when coordinates are absent (denied/timeout → coarse fallback).
121
+ */
122
+ function geoHeadersFromBody(geo) {
123
+ const headers = {};
124
+ if (!geo || typeof geo !== "object") return headers;
125
+ const g = geo;
126
+ const lat = Number(g.latitude);
127
+ const lon = Number(g.longitude);
128
+ if (typeof g.latitude === "string" && Number.isFinite(lat) && lat >= -90 && lat <= 90) headers["x-polyx-geo-lat"] = g.latitude;
129
+ if (typeof g.longitude === "string" && Number.isFinite(lon) && lon >= -180 && lon <= 180) headers["x-polyx-geo-lon"] = g.longitude;
130
+ if (typeof g.accuracyMeters === "number" && Number.isFinite(g.accuracyMeters) && g.accuracyMeters >= 0) headers["x-polyx-geo-accuracy"] = String(g.accuracyMeters);
131
+ if (g.consent === "granted" || g.consent === "denied" || g.consent === "revoked") headers["x-polyx-geo-consent"] = g.consent;
132
+ return headers;
133
+ }
116
134
  /** Read the current session — safe in Server Components (no cookie write). */
117
135
  async function auth(overrides) {
118
136
  const config = resolveNextConfig(overrides);
@@ -169,6 +187,7 @@ function createAuthHandlers(handlersConfig = {}) {
169
187
  } catch {
170
188
  return Response.json({ status: "invalid_request" }, { status: 400 });
171
189
  }
190
+ const geoHeaders = geoHeadersFromBody(payload.geo);
172
191
  const email = typeof payload.email === "string" ? payload.email : "";
173
192
  const password = typeof payload.password === "string" ? payload.password : "";
174
193
  if (!email || !password) return Response.json({ status: "invalid_request" }, { status: 400 });
@@ -190,7 +209,10 @@ function createAuthHandlers(handlersConfig = {}) {
190
209
  });
191
210
  switch (outcome.type) {
192
211
  case "authorized":
193
- await newSession(adapt(await (0, next_headers.cookies)()), config, secure).establishFromCode(outcome.code, verifier, redirectUri, collectForwardedDeviceHeaders(request));
212
+ await newSession(adapt(await (0, next_headers.cookies)()), config, secure).establishFromCode(outcome.code, verifier, redirectUri, {
213
+ ...collectForwardedDeviceHeaders(request),
214
+ ...geoHeaders
215
+ });
194
216
  return Response.json({
195
217
  status: "success",
196
218
  redirectTo: afterSignInPath
package/dist/server.mjs CHANGED
@@ -112,6 +112,24 @@ function collectForwardedDeviceHeaders(request) {
112
112
  if (clientIp) forwarded["x-forwarded-for"] = clientIp;
113
113
  return forwarded;
114
114
  }
115
+ /**
116
+ * Build the forwarded precise-location headers (`x-polyx-geo-*`) from the browser's login
117
+ * body (v6, FR-LOC-7). The browser captures a consented position client-side and posts it;
118
+ * the platform reads these on the token exchange. Only well-formed values are forwarded, and
119
+ * the consent state rides even when coordinates are absent (denied/timeout → coarse fallback).
120
+ */
121
+ function geoHeadersFromBody(geo) {
122
+ const headers = {};
123
+ if (!geo || typeof geo !== "object") return headers;
124
+ const g = geo;
125
+ const lat = Number(g.latitude);
126
+ const lon = Number(g.longitude);
127
+ if (typeof g.latitude === "string" && Number.isFinite(lat) && lat >= -90 && lat <= 90) headers["x-polyx-geo-lat"] = g.latitude;
128
+ if (typeof g.longitude === "string" && Number.isFinite(lon) && lon >= -180 && lon <= 180) headers["x-polyx-geo-lon"] = g.longitude;
129
+ if (typeof g.accuracyMeters === "number" && Number.isFinite(g.accuracyMeters) && g.accuracyMeters >= 0) headers["x-polyx-geo-accuracy"] = String(g.accuracyMeters);
130
+ if (g.consent === "granted" || g.consent === "denied" || g.consent === "revoked") headers["x-polyx-geo-consent"] = g.consent;
131
+ return headers;
132
+ }
115
133
  /** Read the current session — safe in Server Components (no cookie write). */
116
134
  async function auth(overrides) {
117
135
  const config = resolveNextConfig(overrides);
@@ -168,6 +186,7 @@ function createAuthHandlers(handlersConfig = {}) {
168
186
  } catch {
169
187
  return Response.json({ status: "invalid_request" }, { status: 400 });
170
188
  }
189
+ const geoHeaders = geoHeadersFromBody(payload.geo);
171
190
  const email = typeof payload.email === "string" ? payload.email : "";
172
191
  const password = typeof payload.password === "string" ? payload.password : "";
173
192
  if (!email || !password) return Response.json({ status: "invalid_request" }, { status: 400 });
@@ -189,7 +208,10 @@ function createAuthHandlers(handlersConfig = {}) {
189
208
  });
190
209
  switch (outcome.type) {
191
210
  case "authorized":
192
- await newSession(adapt(await cookies()), config, secure).establishFromCode(outcome.code, verifier, redirectUri, collectForwardedDeviceHeaders(request));
211
+ await newSession(adapt(await cookies()), config, secure).establishFromCode(outcome.code, verifier, redirectUri, {
212
+ ...collectForwardedDeviceHeaders(request),
213
+ ...geoHeaders
214
+ });
193
215
  return Response.json({
194
216
  status: "success",
195
217
  redirectTo: afterSignInPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poly-x/next",
3
- "version": "0.1.0-alpha.14",
3
+ "version": "0.1.0-alpha.15",
4
4
  "description": "PolyX SDK for Next.js App Router - components plus server helpers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,8 +47,8 @@
47
47
  "module": "./dist/index.mjs",
48
48
  "types": "./dist/index.d.cts",
49
49
  "dependencies": {
50
- "@poly-x/core": "0.1.0-alpha.14",
51
- "@poly-x/react": "0.1.0-alpha.14"
50
+ "@poly-x/react": "0.1.0-alpha.15",
51
+ "@poly-x/core": "0.1.0-alpha.15"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "next": ">=14",