@suveren/gateway 0.3.12 → 0.3.14

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.
@@ -27,7 +27,11 @@
27
27
  "scopes": ["w_member_social"],
28
28
  "credentialKeys": { "clientId": "clientId", "clientSecret": "clientSecret" },
29
29
  "tokenStorage": "accessToken",
30
- "extraParams": {}
30
+ "extraParams": {},
31
+ "healthCheck": {
32
+ "url": "https://api.linkedin.com/v2/me",
33
+ "accountFields": ["localizedFirstName", "localizedLastName"]
34
+ }
31
35
  },
32
36
  "toolGating": {
33
37
  "default": {
@@ -1724,6 +1724,12 @@ function resolveOrigin(req) {
1724
1724
  }
1725
1725
  var oauthRedirectUris = /* @__PURE__ */ new Map();
1726
1726
  var manifestCache = null;
1727
+ function resolvePath(obj, path) {
1728
+ const v = path.split(".").reduce((acc, key) => {
1729
+ return acc && typeof acc === "object" ? acc[key] : void 0;
1730
+ }, obj);
1731
+ return v == null ? void 0 : String(v);
1732
+ }
1727
1733
  function decodeJwtEmail(idToken) {
1728
1734
  if (!idToken) return void 0;
1729
1735
  try {
@@ -1864,7 +1870,27 @@ app.get("/auth/oauth/:integrationId/health", authGuard, async (req, res) => {
1864
1870
  return;
1865
1871
  }
1866
1872
  if (!/refresh/i.test(oauth.tokenStorage)) {
1867
- res.json({ status: "unverified", account });
1873
+ const hc = oauth.healthCheck;
1874
+ if (!hc?.url) {
1875
+ res.json({ status: "unverified", account });
1876
+ return;
1877
+ }
1878
+ try {
1879
+ const r = await fetch(hc.url, { headers: { Authorization: `Bearer ${token}` } });
1880
+ if (r.ok) {
1881
+ const data = await r.json().catch(() => ({}));
1882
+ const probed = (hc.accountFields ?? []).map((f) => resolvePath(data, f)).filter((v) => !!v).join(" ").trim();
1883
+ res.json({ status: "ok", account: probed || account });
1884
+ return;
1885
+ }
1886
+ if (r.status === 401 || r.status === 403) {
1887
+ res.json({ status: "failed", account, error: `token rejected (HTTP ${r.status})` });
1888
+ return;
1889
+ }
1890
+ res.json({ status: "unverified", account });
1891
+ } catch (err) {
1892
+ res.json({ status: "unverified", account, error: err instanceof Error ? err.message : "probe failed" });
1893
+ }
1868
1894
  return;
1869
1895
  }
1870
1896
  try {