suppa-mcp-2 1.42.3 → 1.42.4

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.
Files changed (2) hide show
  1. package/dist/auth.js +59 -9
  2. package/package.json +1 -1
package/dist/auth.js CHANGED
@@ -124,16 +124,19 @@ export function extractCredentials(body, setCookies) {
124
124
  (typeof b.refresh_token === "string" ? b.refresh_token : "") ||
125
125
  "";
126
126
  }
127
- for (const cookie of setCookies) {
128
- const eq = cookie.indexOf("=");
129
- const name = (eq === -1 ? cookie : cookie.slice(0, eq)).trim();
130
- const rest = eq === -1 ? "" : cookie.slice(eq + 1);
131
- const val = rest.split(";", 1)[0].trim();
127
+ // The auth service answers with more than the two token cookies, in this order: an emptied
128
+ // `accessToken` and `refreshToken` (Max-Age=0 — it expires the other SameSite variant, BSU-3077),
129
+ // the device cookie `suppa_did`, and only then the real `accessToken` and `refreshToken`. So the
130
+ // first cookie of a name is not the token: take the first one that has a value and is not expired.
131
+ for (const { name, value, expired } of setCookies.flatMap(splitSetCookieHeader).map(parseSetCookie)) {
132
+ if (!value || expired) {
133
+ continue;
134
+ }
132
135
  if (name === "accessToken" && !access) {
133
- access = val;
136
+ access = value;
134
137
  }
135
138
  else if (name === "refreshToken" && !refresh) {
136
- refresh = val;
139
+ refresh = value;
137
140
  }
138
141
  }
139
142
  if (access && !aExp) {
@@ -149,6 +152,48 @@ export function extractCredentials(body, setCookies) {
149
152
  refreshExp: rExp,
150
153
  };
151
154
  }
155
+ /**
156
+ * Split a Set-Cookie value that holds several cookies joined with ", " — what `headers.get()`
157
+ * gives on a runtime without `getSetCookie`, or behind a proxy that folds the header — back into
158
+ * one cookie each. A comma starts a new cookie only when a `name=` follows it, so the comma inside
159
+ * `Expires=Thu, 01 Jan 1970 …` stays where it is.
160
+ */
161
+ export function splitSetCookieHeader(value) {
162
+ return value
163
+ .split(/,(?=\s*[!#$%&'*+\-.^_`|~0-9A-Za-z]+=)/)
164
+ .map((part) => part.trim())
165
+ .filter(Boolean);
166
+ }
167
+ /** One Set-Cookie line: its name, its value, and whether it deletes the cookie instead of setting it. */
168
+ function parseSetCookie(line) {
169
+ const [pair, ...attributes] = line.split(";");
170
+ const eq = pair.indexOf("=");
171
+ const name = (eq === -1 ? pair : pair.slice(0, eq)).trim();
172
+ const value = eq === -1 ? "" : pair.slice(eq + 1).trim();
173
+ let expired = false;
174
+ for (const attribute of attributes) {
175
+ const at = attribute.indexOf("=");
176
+ const key = (at === -1 ? attribute : attribute.slice(0, at)).trim().toLowerCase();
177
+ const arg = at === -1 ? "" : attribute.slice(at + 1).trim();
178
+ if (key === "max-age" && Number(arg) <= 0) {
179
+ expired = true;
180
+ }
181
+ else if (key === "expires" && Date.parse(arg) <= Date.now()) {
182
+ expired = true;
183
+ }
184
+ }
185
+ return { name, value, expired };
186
+ }
187
+ /** The cookies a response set, by name only — never a value — for an error that has to say what came. */
188
+ export function describeSetCookies(setCookies) {
189
+ const cookies = setCookies.flatMap(splitSetCookieHeader).map(parseSetCookie);
190
+ if (cookies.length === 0) {
191
+ return "no Set-Cookie at all";
192
+ }
193
+ return cookies
194
+ .map(({ name, value, expired }) => `${name}${!value ? " (empty)" : expired ? " (expired)" : ""}`)
195
+ .join(", ");
196
+ }
152
197
  // ---------------------------------------------------------------------------
153
198
  // Low-level network (auth endpoints only — no tenant auth headers)
154
199
  // ---------------------------------------------------------------------------
@@ -171,9 +216,10 @@ function readSetCookies(headers) {
171
216
  }
172
217
  try {
173
218
  if (typeof h.get === "function") {
219
+ // Without getSetCookie every Set-Cookie line comes back joined into one value.
174
220
  const single = h.get("set-cookie");
175
221
  if (single) {
176
- return [single];
222
+ return splitSetCookieHeader(single);
177
223
  }
178
224
  }
179
225
  }
@@ -527,7 +573,8 @@ export async function doRefresh(baseUrl, host, creds) {
527
573
  }
528
574
  const fresh = extractCredentials(body, cookies);
529
575
  if (!fresh.accessToken) {
530
- recordRefreshFailure(host, `the refresh endpoint returned HTTP 200 with no access token in it (${REFRESH_PATH})`);
576
+ recordRefreshFailure(host, `the refresh endpoint returned HTTP 200 with no access token in it (${REFRESH_PATH}; ` +
577
+ `cookies set: ${describeSetCookies(cookies)})`);
531
578
  throw new ReloginRequired(host);
532
579
  }
533
580
  if (!fresh.refreshToken) {
@@ -784,6 +831,9 @@ export async function login(tenant = "") {
784
831
  if (!creds.accessToken) {
785
832
  return JSON.stringify({
786
833
  error: "Login exchange returned no access token.",
834
+ // Names only, never values: what the platform set tells whether it sent the token at all.
835
+ cookies_set: describeSetCookies(result.cookies),
836
+ node: process.version,
787
837
  host,
788
838
  });
789
839
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.42.3",
3
+ "version": "1.42.4",
4
4
  "description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
5
5
  "type": "module",
6
6
  "bin": {